diff --git a/src/app/utils/consolePasteScamWarning.test.ts b/src/app/utils/consolePasteScamWarning.test.ts new file mode 100644 index 000000000..19af68472 --- /dev/null +++ b/src/app/utils/consolePasteScamWarning.test.ts @@ -0,0 +1,44 @@ +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { installConsolePasteScamWarning } from './consolePasteScamWarning'; + +const isMobileTauri = vi.hoisted(() => vi.fn<() => boolean>()); + +vi.mock('./platform', () => ({ isMobileTauri })); + +describe('installConsolePasteScamWarning', () => { + beforeEach(() => { + vi.useFakeTimers(); + vi.clearAllMocks(); + window.innerWidth = 800; + window.outerWidth = 800; + window.innerHeight = 400; + // A soft keyboard shrinks the viewport by far more than the 160px threshold. + window.outerHeight = 900; + }); + + afterEach(() => { + vi.useRealTimers(); + }); + + it('stays silent on a phone, where the keyboard looks like docked devtools', () => { + isMobileTauri.mockReturnValue(true); + const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined); + + installConsolePasteScamWarning(); + vi.advanceTimersByTime(2000); + + expect(warn).not.toHaveBeenCalled(); + warn.mockRestore(); + }); + + it('still warns on desktop when devtools look docked', () => { + isMobileTauri.mockReturnValue(false); + const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined); + + installConsolePasteScamWarning(); + vi.advanceTimersByTime(2000); + + expect(warn).toHaveBeenCalled(); + warn.mockRestore(); + }); +}); diff --git a/src/app/utils/consolePasteScamWarning.ts b/src/app/utils/consolePasteScamWarning.ts index 72d750e28..2ec701092 100644 --- a/src/app/utils/consolePasteScamWarning.ts +++ b/src/app/utils/consolePasteScamWarning.ts @@ -1,3 +1,5 @@ +import { isMobileTauri } from './platform'; + // This is probably not very accurate, but doesn't really matter I suppose function isDockedDevtoolsLikely(): boolean { const gapW = window.outerWidth - window.innerWidth; @@ -7,6 +9,10 @@ function isDockedDevtoolsLikely(): boolean { } export function installConsolePasteScamWarning(): void { + // A phone has no docked devtools, and the soft keyboard moves the viewport far enough + // to look exactly like one opening. + if (isMobileTauri()) return; + const BANNER_STYLE = 'font-size:56px;font-weight:900;color:#ff0033;background:#1a0006;padding:16px 24px;border:6px solid #ff0033;line-height:1.1;'; const BODY_STYLE =