Skip to content

Commit

Permalink
Exclusions: exclude keys based on the top frame URL, not subframe URLs
Browse files Browse the repository at this point in the history
This fixes #3254, #3960, #4375
  • Loading branch information
philc committed Feb 4, 2024
1 parent 5be5fc1 commit 4fe5484
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
5 changes: 3 additions & 2 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
16 changes: 5 additions & 11 deletions content_scripts/vimium_frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
});

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4fe5484

Please sign in to comment.