Skip to content

Instantly share code, notes, and snippets.

@yellow1234
Created July 4, 2022 22:25
Show Gist options
  • Save yellow1234/20370bd58dd1c0b5f1c385dcb0afe5ac to your computer and use it in GitHub Desktop.
Save yellow1234/20370bd58dd1c0b5f1c385dcb0afe5ac to your computer and use it in GitHub Desktop.
Missing user agent client hints debug example
(function () {
try {
var electron = require('electron');
var {app, BrowserWindow, screen} = electron;
var mainFunc = function () {
try {
const {width, height} = screen.getPrimaryDisplay().workAreaSize;
var win = new BrowserWindow({
width: width,
height: height,
resizable: false,
webPreferences: {
nodeIntegration: false,
contextIsolation: false,
}
});
var filters = [
"*://bing.com/*",
"*://*.bing.com/*",
"*://google.com/*",
"*://*.google.com/*"
]
win.webContents.session.webRequest.onBeforeSendHeaders({urls: filters},
function(details, callback) {
var requestHeaders = details.requestHeaders;
if (!requestHeaders) {
callback({});
return;
}
var url = details.url;
console.log(url);
console.log("ua client hints in request headers:");
for (var hdr in requestHeaders) {
if (hdr.toLowerCase().includes("sec-ch")) {
console.log(hdr, requestHeaders[hdr]);
}
}
callback({});
})
win.webContents.session.webRequest.onHeadersReceived(function (details, callback) {
var responseHeaders = details.responseHeaders;
if (!responseHeaders) {
callback({});
return;
}
var url = details.url;
console.log(url);
console.log("ua client hints in response headers:");
for (var hdr in responseHeaders) {
if (hdr.toLowerCase().includes("accept-ch")) {
console.log(hdr, responseHeaders[hdr]);
}
}
callback({});
});
win.loadURL("https://www.bing.com/search?q=car");
// win.loadURL("https://www.google.com/search?q=car");
} catch (ex) {}
}
app.on("window-all-closed", function() {
try {
app.quit();
} catch (ex) {}
});
app.whenReady()
.then(mainFunc);
} catch (ex) {}
})();
{
"name": "app",
"main": "main.js",
"version": "1.0"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment