mirror of https://github.com/gorhill/uBlock.git
Make use of `X-DNS-Prefetch-Control` in Chromium-based browsers
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/548 The fix applies only to Chromium-based browsers -- a `X-DNS-Prefetch-Control` header[1] will be unconditionally injected when uBO's "Disable pre-fetching" setting is enabled (it is by default). This is a mitigation, this does not completely fix the issue of the setting "Disable pre-fetching" being disregarded on Chromium-based browsers when sites use `preconnect`/`preload`. [1] https://developer.mozilla.org/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control
This commit is contained in:
parent
acb12d2a1d
commit
367cdd6666
|
@ -223,8 +223,9 @@ vAPI.browserSettings = (function() {
|
|||
}
|
||||
switch ( setting ) {
|
||||
case 'prefetching':
|
||||
const enabled = !!details[setting];
|
||||
try {
|
||||
if ( !!details[setting] ) {
|
||||
if ( enabled ) {
|
||||
chrome.privacy.network.networkPredictionEnabled.clear({
|
||||
scope: 'regular'
|
||||
}, vAPI.resetLastError);
|
||||
|
@ -237,6 +238,9 @@ vAPI.browserSettings = (function() {
|
|||
} catch(ex) {
|
||||
console.error(ex);
|
||||
}
|
||||
if ( vAPI.prefetching instanceof Function ) {
|
||||
vAPI.prefetching(enabled);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'hyperlinkAuditing':
|
||||
|
|
|
@ -195,3 +195,39 @@ vAPI.net.onBeforeReady = vAPI.net.onBeforeReady || (function() {
|
|||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// https://github.com/uBlockOrigin/uBlock-issues/issues/548
|
||||
// Use `X-DNS-Prefetch-Control` to workaround Chromium's disregard of the
|
||||
// setting "Predict network actions to improve page load performance".
|
||||
|
||||
vAPI.prefetching = (function() {
|
||||
let listening = false;
|
||||
|
||||
const onHeadersReceived = function(details) {
|
||||
details.responseHeaders.push({
|
||||
name: 'X-DNS-Prefetch-Control',
|
||||
value: 'off'
|
||||
});
|
||||
return { responseHeaders: details.responseHeaders };
|
||||
};
|
||||
|
||||
return state => {
|
||||
const wr = chrome.webRequest;
|
||||
if ( state && listening ) {
|
||||
wr.onHeadersReceived.removeListener(onHeadersReceived);
|
||||
listening = false;
|
||||
} else if ( !state && !listening ) {
|
||||
wr.onHeadersReceived.addListener(
|
||||
onHeadersReceived,
|
||||
{
|
||||
urls: [ 'http://*/*', 'https://*/*' ],
|
||||
types: [ 'main_frame', 'sub_frame' ]
|
||||
},
|
||||
[ 'blocking', 'responseHeaders' ]
|
||||
);
|
||||
listening = true;
|
||||
}
|
||||
};
|
||||
})();
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
Loading…
Reference in New Issue