mirror of
https://github.com/Llewellynvdm/nativefier.git
synced 2024-12-23 02:28:55 +00:00
See Electron 3.0 breaking API changes: https://electronjs.org/blog/electron-3-0#breaking-api-changes [#12477] https://github.com/electron/electron/pull/12477 refactor: removed `did-get-response-details` and `did-get-redirect-request events`
This commit is contained in:
parent
038812cd46
commit
114b4a9724
@ -43,20 +43,24 @@ function maybeInjectCss(browserWindow) {
|
|||||||
const injectCss = () => {
|
const injectCss = () => {
|
||||||
browserWindow.webContents.insertCSS(cssToInject);
|
browserWindow.webContents.insertCSS(cssToInject);
|
||||||
};
|
};
|
||||||
|
const onHeadersReceived = (details, callback) => {
|
||||||
|
injectCss();
|
||||||
|
callback({ cancel: false, responseHeaders: details.responseHeaders });
|
||||||
|
};
|
||||||
|
|
||||||
browserWindow.webContents.on('did-finish-load', () => {
|
browserWindow.webContents.on('did-finish-load', () => {
|
||||||
// remove the injection of css the moment the page is loaded
|
// remove the injection of css the moment the page is loaded
|
||||||
browserWindow.webContents.removeListener(
|
browserWindow.webContents.session.webRequest.onHeadersReceived(null);
|
||||||
'did-get-response-details',
|
|
||||||
injectCss,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// on every page navigation inject the css
|
// on every page navigation inject the css
|
||||||
browserWindow.webContents.on('did-navigate', () => {
|
browserWindow.webContents.on('did-navigate', () => {
|
||||||
// we have to inject the css in did-get-response-details to prevent the fouc
|
// we have to inject the css in onHeadersReceived to prevent the fouc
|
||||||
// will run multiple times
|
// will run multiple times
|
||||||
browserWindow.webContents.on('did-get-response-details', injectCss);
|
browserWindow.webContents.session.webRequest.onHeadersReceived(
|
||||||
|
null,
|
||||||
|
onHeadersReceived,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user