Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix opening links twice when privacy.resistFingerprinting is enabled or on Firefox 91.6+ #4000

Merged
merged 3 commits into from
May 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions background_scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ const TabOperations = {
delete tabConfig["url"];

// Firefox <57 throws an error when openerTabId is used (issue 1238314).
const canUseOpenerTabId = !(Utils.isFirefox() && (Utils.compareVersions(Utils.firefoxVersion(), "57") < 0));
const canUseOpenerTabId = !Utils.isFirefox() || Utils.firefoxVersion() instanceof Promise
|| (Utils.compareVersions(Utils.firefoxVersion(), "57") >= 0);
if (canUseOpenerTabId)
tabConfig.openerTabId = request.tab.id;

Expand Down Expand Up @@ -436,7 +437,20 @@ var Frames = {
onConnect(sender, port) {
const [tabId, frameId] = [sender.tab.id, sender.frameId];
port.onDisconnect.addListener(() => Frames.unregisterFrame({tabId, frameId, port}));
port.postMessage({handler: "registerFrameId", chromeFrameId: frameId});
const message = {handler: "registerFrameId", chromeFrameId: frameId}
let firefoxVersion
if (Utils.isFirefox()) {
firefoxVersion = Utils.firefoxVersion()
message.firefoxVersion = firefoxVersion
}
if (typeof firefoxVersion === "object") {
firefoxVersion.then(() => {
message.firefoxVersion = Utils.firefoxVersion()
port.postMessage(message);
})
} else {
port.postMessage(message);
}
(portsForTab[tabId] != null ? portsForTab[tabId] : (portsForTab[tabId] = {}))[frameId] = port;

// Return our onMessage handler for this port.
Expand Down
7 changes: 5 additions & 2 deletions content_scripts/vimium_frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,11 @@ var Frame = {
return HintCoordinator[request.messageType](request);
},

registerFrameId({chromeFrameId}) {
frameId = (root.frameId = (window.frameId = chromeFrameId));
registerFrameId(request) {
frameId = (root.frameId = (window.frameId = request.chromeFrameId));
if (Utils.isFirefox()) {
Utils.firefoxVersion = () => request.firefoxVersion
}
// We register a frame immediately only if it is focused or its window isn't tiny. We register tiny
// frames later, when necessary. This affects focusFrame() and link hints.
if (windowIsFocused() || !DomUtils.windowIsTooSmall()) {
Expand Down
5 changes: 2 additions & 3 deletions lib/dom_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,8 @@ var DomUtils = {
for (let event of eventSequence) {
// In firefox prior to 96, simulating a click on an element would be blocked. In 96+,
// extensions can trigger native click listeners on elements. See #3985.
const mayBeBlocked =
event === "click" && Utils.isFirefox() && !navigator.userAgentData &&
parseInt((navigator.userAgent.match(/\bFirefox\/(\d+)/) || [0, 96])[1]) < 96
const mayBeBlocked = event === "click" && Utils.isFirefox() && parseInt(Utils.firefoxVersion()) < 96
&& /^91\.[0-5](\.|$)/.test(Utils.firefoxVersion())
const defaultActionShouldTrigger =
mayBeBlocked && (Object.keys(modifiers).length === 0) &&
(element.target === "_blank") && element.href &&
Expand Down
12 changes: 8 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ if (window.forTrusted == null) {
});
}

// TODO(philc): The comment below about its usage doesn't make sense to me. Can we replace this with
// window.navigator?
// Note(gdh1995): Info in navigator is not reliable, because sometimes browsers will provide fake values.
// For example, when `privacy.resistFingerprinting` is enabled on `about:config` of Firefox.
let browserInfo = null;
if (window.browser && browser.runtime && browser.runtime.getBrowserInfo)
browserInfo = browser.runtime.getBrowserInfo();
Expand All @@ -31,13 +31,17 @@ var Utils = {
return () => isFirefox;
})(),

// NOTE(gdh1995): Content scripts may access this only after `registerFrameId`
firefoxVersion: (function() {
// NOTE(mrmr1993): This only works in the background page.
let ffVersion = undefined;
if (browserInfo) {
browserInfo.then(browserInfo => ffVersion = browserInfo != null ? browserInfo.version : undefined);
browserInfo.then(info => {
ffVersion = info != null ? info.version : undefined
browserInfo = undefined
});
}
return () => ffVersion;
return () => ffVersion || browserInfo;
})(),

getCurrentVersion() {
Expand Down