Вот код:
Код: Выделить всё
await browser.scripting.executeScript({
target: details,
world: "MAIN",
injectImmediately: true,
args: [tabId, frameId],
func: (tabId, frameId) => {
if (window.history.__pushState) {
console.warn("Already injected");
return;
}
window.history.__pushState = history.pushState;
console.log("Injected pushState()");
history.pushState = function(state, unused, url) {
// eslint-disable-next-line no-console
console.log("Intercepted pushState()", state, unused, url);
window.history.__pushState(state, unused, url);
console.log("debug", browser); // `browser` is undefined
browser.runtime.sendMessage({
type: "safari-onhistorystateupdated",
state, unused, url
});
};
}
});
Подробнее здесь: https://stackoverflow.com/questions/796 ... ipting-exe