diff --git a/content/extend_click.ts b/content/extend_click.ts index ba679c41c..fa2806e26 100644 --- a/content/extend_click.ts +++ b/content/extend_click.ts @@ -143,7 +143,7 @@ export const ec_main_not_ff = (Build.BTypes !== BrowserType.Firefox as number ? } ; (box as HTMLElement).textContent = "" if (mismatch) { - if (!Build.NDEBUG && target && !isSafe) { + if (!Build.NDEBUG && target && !isSafe && (kInjectManually || target as EventTarget !== window)) { console.error("extend click: unexpected: detail =", rawDetail, target); } return; @@ -227,8 +227,9 @@ export const ec_main_not_ff = (Build.BTypes !== BrowserType.Firefox as number ? } if (!kInjectManually) { if (grabBackFocus) { + dispatchEvent(new Event(kVOnClick1)) setupEventListener(0, kVOnClick1, onClick); - OnDocLoaded_(() => { // check CSP script-src or JS-disabled-in-CS + box || OnDocLoaded_(() => { // check CSP script-src or JS-disabled-in-CS box || execute(kContentCmd.Destroy) }) } diff --git a/content/extend_click_vc.ts b/content/extend_click_vc.ts index a3135dc5f..bd3df0c2c 100644 --- a/content/extend_click_vc.ts +++ b/content/extend_click_vc.ts @@ -274,8 +274,13 @@ const onDocOpen = (isWrite?: 0 | 2, oriHref?: string): void => { } } const noop = (): 1 => { return 1 } -const defineProp = Object.defineProperty -const dataset = (root as Element as TypeToAssert).dataset +const docEl = doc0.documentElement; +(function startHook(delayed?: 1): void { + if (!docEl || delayed && !(!docEl.lastChild && docEl.parentNode === doc0)) { + return + } + const dataset = (root as Element as TypeToAssert).dataset + const defineProp = Object.defineProperty if (dataset && ( dataset.vimium = kRC, // only the below can affect outsides @@ -317,6 +322,15 @@ if (dataset && ( } }) } +} else if (!delayed) { + const listenOpt: EventListenerOptions = { capture: true, once: true } + const postStart = (event: EventToPrevent): void => { + queueMicroTask_((): void => startHook(1)) + call(StopProp, event) + } + _listen(kOC, postStart, listenOpt) + _listen("readystatechange", removeEventListener.bind(window, kOC, postStart, listenOpt), listenOpt) } +})() })()