From 4fe548455ec2c2eb00a35080115c16ad5765db63 Mon Sep 17 00:00:00 2001 From: Phil Crosby Date: Fri, 12 Jan 2024 19:00:10 -0800 Subject: [PATCH] Exclusions: exclude keys based on the top frame URL, not subframe URLs This fixes #3254, #3960, #4375 --- background_scripts/main.js | 5 +++-- content_scripts/vimium_frontend.js | 16 +++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/background_scripts/main.js b/background_scripts/main.js index ab8eb9e19..b122610fc 100644 --- a/background_scripts/main.js +++ b/background_scripts/main.js @@ -561,9 +561,10 @@ const sendRequestHandlers = { async initializeFrame(request, sender) { const tabId = sender.tab.id; - const enabledState = Exclusions.isEnabledForUrl(request.url); + const enabledState = Exclusions.isEnabledForUrl(request.topFrameUrl); - if (request.frameIsFocused) { + const isTopFrame = sender.frameId == 0; + if (isTopFrame) { let whichIcon; if (!enabledState.isEnabledForUrl) { whichIcon = "disabled"; diff --git a/content_scripts/vimium_frontend.js b/content_scripts/vimium_frontend.js index bcba35576..adf290cb4 100644 --- a/content_scripts/vimium_frontend.js +++ b/content_scripts/vimium_frontend.js @@ -199,7 +199,7 @@ const initializePreDomReady = async function () { // NOTE(philc): I'm blocking further Vimium initialization on this, for simplicity. If necessary // we could allow other tasks to run concurrently. await Settings.onLoaded(); - checkIfEnabledForUrl(document.hasFocus()); + checkIfEnabledForUrl(); const requestHandlers = { getFocusStatus(_request, _sender) { @@ -308,7 +308,7 @@ const installListeners = Utils.makeIdempotent(function () { // Whenever we get the focus, check if we should be enabled. const onFocus = forTrusted(function (event) { if (event.target === window) { - checkIfEnabledForUrl(true); + checkIfEnabledForUrl(); } }); @@ -407,17 +407,11 @@ globalThis.lastFocusedInput = (function () { return () => recentlyFocusedElement; })(); -// Checks if Vimium should be enabled or not in this frame. As a side effect, it also informs the -// background page whether this frame has the focus, allowing the background page to change the -// Vimium Action icon to indicate whether the curent page is excluded in Vimium. -const checkIfEnabledForUrl = async (frameIsFocused) => { - if (frameIsFocused == null) { - frameIsFocused = windowIsFocused(); - } +// Checks if Vimium should be enabled or not based on the top frame's URL. +const checkIfEnabledForUrl = async () => { const response = await chrome.runtime.sendMessage({ handler: "initializeFrame", - frameIsFocused, - url: window.location.toString(), + topFrameUrl: window.top.location.toString(), }); isEnabledForUrl = response.isEnabledForUrl;