Skip to content

Commit

Permalink
MV3: extend_click: now support reverse execution order
Browse files Browse the repository at this point in the history
after browser restarts, ec_vc may run before frontend
  • Loading branch information
gdh1995 committed Jan 7, 2024
1 parent 8d3749d commit 538111e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions content/extend_click.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
})
}
Expand Down
18 changes: 16 additions & 2 deletions content/extend_click_vc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Element, HTMLElement, "dataset", "tagName">).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<Element, HTMLElement, "dataset", "tagName">).dataset
const defineProp = Object.defineProperty
if (dataset && (
dataset.vimium = kRC,
// only the below can affect outsides
Expand Down Expand Up @@ -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)
}
})()

})()

0 comments on commit 538111e

Please sign in to comment.