mirror of
https://github.com/gorhill/uMatrix.git
synced 2024-09-30 00:56:32 +13:00
Use different page navigation detection for Safari
The beforeNavigate event wasn't reliable (sometimes didn't fire, sometimes fired unnecessary when opening a link with the middle click - which had a workaround previously, but that's also removed by this commit). When the event didn't fire, the bindTabToPageStats method didn't run, and the requests related to the tab weren't blocked.
This commit is contained in:
parent
ed1e23cfb1
commit
d150eb6d1c
1 changed files with 12 additions and 15 deletions
|
@ -256,7 +256,13 @@ if (self.chrome) {
|
||||||
var response = safari.self.tab.canLoad(e, details);
|
var response = safari.self.tab.canLoad(e, details);
|
||||||
|
|
||||||
if (!response) {
|
if (!response) {
|
||||||
e.preventDefault();
|
if (details.type === 'main_frame') {
|
||||||
|
window.stop();
|
||||||
|
throw Error;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// local mirroring, response is a data: URL here
|
// local mirroring, response is a data: URL here
|
||||||
|
@ -350,20 +356,11 @@ if (self.chrome) {
|
||||||
|
|
||||||
self.addEventListener('contextmenu', onContextMenu, true);
|
self.addEventListener('contextmenu', onContextMenu, true);
|
||||||
|
|
||||||
self.addEventListener('mouseup', function(e) {
|
// 'main_frame' simulation
|
||||||
if (e.button !== 1) {
|
onBeforeLoad(beforeLoadEvent, {
|
||||||
return;
|
url: window.location.href,
|
||||||
}
|
type: 'main_frame'
|
||||||
|
});
|
||||||
e = document.evaluate('ancestor-or-self::a[@href]', e.target, null, 9, null).singleNodeValue;
|
|
||||||
|
|
||||||
if (e && /^https?:$/.test(e.protocol)) {
|
|
||||||
safari.self.tab.canLoad(beforeLoadEvent, {
|
|
||||||
middleClickURL: e.href,
|
|
||||||
timeStamp: Date.now()
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
Loading…
Reference in a new issue