From b0436687b36e814c0321415a701fd96be68e2404 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Sun, 21 Jul 2024 02:42:40 +0800 Subject: [PATCH] MV3: now order of extend_click_vc is reliable --- content/commands.ts | 2 +- content/extend_click.ts | 7 +++++-- content/extend_click_vc.ts | 19 ++++++++++--------- manifest.json | 16 ++++++++++------ scripts/uglifyjs-mangle.js | 2 +- 5 files changed, 27 insertions(+), 19 deletions(-) diff --git a/content/commands.ts b/content/commands.ts index 8eae12811..8184ca032 100644 --- a/content/commands.ts +++ b/content/commands.ts @@ -84,7 +84,7 @@ set_contentCommands_([ /* kFgCmd.visualMode: */ visualActivate, /* kFgCmd.vomnibar: */ omniActivate, /* kFgCmd.insertMode: */ (opt: CmdOptions[kFgCmd.insertMode]): void => { - if (opt.u) { + if (opt.u) { /*#__ENABLE_SCOPED__*/ const done = derefInDoc_(lastHovered_) ? 0 : 2 void catchAsyncErrorSilently(wrap_enable_bubbles(opt, unhover_async<1>, [])).then((): void => { hudTip(kTip.didUnHoverLast) diff --git a/content/extend_click.ts b/content/extend_click.ts index 29060e068..5dec68e1c 100644 --- a/content/extend_click.ts +++ b/content/extend_click.ts @@ -242,9 +242,12 @@ export const ec_main_not_ff = (Build.BTypes !== BrowserType.Firefox as number ? } if (!kInjectManually) { if (grabBackFocus) { - dispatchEvent(new Event(kVOnClick1)) // it seems MS Edge may get a wrong order between dynamic and static scripts + if (Build.BTypes & ~BrowserType.Chrome || Build.MinCVer < BrowserVer.MinCSAcceptWorldInManifest) { + // MS Edge may get a wrong order between dynamic and static scripts, but not reproduced on Chrome / Edge 126 + dispatchEvent(new Event(kVOnClick1)) + } setupEventListener(0, kVOnClick1, onClick); - box || OnDocLoaded_(() => { // check CSP script-src or JS-disabled-in-CS + 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 4ae21462f..7abdebfbe 100644 --- a/content/extend_click_vc.ts +++ b/content/extend_click_vc.ts @@ -1,5 +1,5 @@ "use strict"; -Build.MV3 && Build.BTypes & BrowserType.Chrome && (function VC(this: void): void { +Build.MV3 && Build.BTypes & BrowserType.Chrome && (function VC(this: void, delayed?: 1): void { const enum InnerConsts { MaxElementsInOneTickDebug = 1024, MaxElementsInOneTickRelease = 512, @@ -290,18 +290,20 @@ const onDocOpen = (isWrite?: 0 | 2, oriHref?: string): void => { } const noop = (): 1 => { return 1 } const docEl = doc0.documentElement; -(function startHook(delayed?: 1): void { - if (!docEl || delayed && !(!docEl.lastChild && docEl.parentNode === doc0)) { +const defineProp = Object.defineProperty, dbgLoc = Build.NDEBUG ? null as never : location +const dataset = (root as Element as TypeToAssert).dataset +if (!docEl || (Build.BTypes & ~BrowserType.Chrome || Build.MinCVer < BrowserVer.MinCSAcceptWorldInManifest) + && delayed && !(!docEl.lastChild && docEl.parentNode === doc0)) { return - } - const dataset = (root as Element as TypeToAssert).dataset +} if (dataset && ( dataset.vimium = kRC, + // only the below can affect outsides + _dispatch(new DECls(kOC, {relatedTarget: root})), !dataset.vimium )) { - const defineProp = Object.defineProperty, dbgLoc = Build.NDEBUG ? null as never : location root[kAEL](InnerConsts.kCmd, executeCmd, !0) timer = toRegister.length > 0 ? setTimeout_(next, InnerConsts.DelayForNext) : 0 ETP[kAEL] = myAEL @@ -337,15 +339,14 @@ if (dataset && ( } }) } -} else if (!delayed) { +} else if ((Build.BTypes & ~BrowserType.Chrome || Build.MinCVer < BrowserVer.MinCSAcceptWorldInManifest) && !delayed) { const listenOpt: EventListenerOptions = { capture: true, once: true } const postStart = (event: EventToPrevent): void => { - queueMicroTask_((): void => startHook(1)) + queueMicroTask_((): void => VC(1)) call(StopProp, event) } _listen(kOC, postStart, listenOpt) _listen("readystatechange", removeEventListener.bind(window, kOC, postStart, listenOpt), listenOpt) } -})() })() diff --git a/manifest.json b/manifest.json index 16302f9c9..b57b3cfed 100644 --- a/manifest.json +++ b/manifest.json @@ -12,12 +12,6 @@ "service_worker": "background/worker.js", "type": "module" }, - "browser_specific_settings": { - "gecko": { - "id": "vimium-c.dev@gdh1995.cn", - "strict_min_version": "119.0" - } - }, "commands": { "createTab": { "description": "__MSG_createTab_s__" }, "goBack": { "description": "__MSG_goBack_s__" }, @@ -62,6 +56,16 @@ "match_origin_as_fallback": true, "matches": [ "" ], "run_at": "document_start" + }, { + "all_frames": true, + "js": [ + "content/extend_click_vc.js" + ], + "match_about_blank": true, + "match_origin_as_fallback": true, + "matches": [ "" ], + "run_at": "document_start", + "world": "MAIN" } ], "content_security_policy": { "extension_pages": "script-src 'self'; style-src 'self' 'unsafe-inline'; object-src 'none'" diff --git a/scripts/uglifyjs-mangle.js b/scripts/uglifyjs-mangle.js index 010ebad59..1744ef708 100644 --- a/scripts/uglifyjs-mangle.js +++ b/scripts/uglifyjs-mangle.js @@ -8,7 +8,7 @@ const MIN_LONG_STRING = 20; const MIN_STRING_LENGTH_TO_COMPUTE_GAIN = 2; const MIN_EXPECTED_STRING_GAIN = 11; const ALLOWED_SHORT_NAMES = new Set([ - ":SP:0", ":BU:0", ":V:0", ":I:0", ":V:1", ":I:1" + ":SP:0", ":BU:0", ":V:0", ":I:0", ":V:1", ":I:1", ":VC:0" ]) // @ts-ignore