Skip to content

Commit

Permalink
Use the tab's URL to check if the Vimium is enabled
Browse files Browse the repository at this point in the history
Previously we were accessing the top frame's URL, which fails due to cross-origin restrictions if
the frames are from different origins.
  • Loading branch information
philc committed Feb 4, 2024
1 parent 38278b8 commit 839c38e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 4 additions & 3 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,9 @@ const sendRequestHandlers = {
},

async initializeFrame(request, sender) {
const tabId = sender.tab.id;
const enabledState = Exclusions.isEnabledForUrl(request.topFrameUrl);
// Check whether the extension is enabled for the top frame's URL, rather than the URL of the
// specific frame that sent this request.
const enabledState = Exclusions.isEnabledForUrl(sender.tab.url);

const isTopFrame = sender.frameId == 0;
if (isTopFrame) {
Expand All @@ -588,7 +589,7 @@ const sendRequestHandlers = {
"32": "../icons/action_disabled_32.png",
},
};
chrome.action.setIcon({ path: iconSet[whichIcon], tabId: tabId });
chrome.action.setIcon({ path: iconSet[whichIcon], tabId: sender.tab.id });
}

const response = Object.assign({
Expand Down
5 changes: 1 addition & 4 deletions content_scripts/vimium_frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,7 @@ globalThis.lastFocusedInput = (function () {

// 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",
topFrameUrl: window.top.location.toString(),
});
const response = await chrome.runtime.sendMessage({ handler: "initializeFrame" });

isEnabledForUrl = response.isEnabledForUrl;

Expand Down

0 comments on commit 839c38e

Please sign in to comment.