我正在开发一个 Chrome 扩展来调整 Facebook。但是,如 Facebook 等支持 HTML5 的网站中捕获浏览操作需要覆盖 window.history.pushState
,如 in this SO question 所述。 .
不幸的是,Chrome 的隔离世界似乎阻止了这种覆盖。除了轮询 document.location.href
之外,还有其他捕获历史更改的方法吗?
最佳答案
不确定您是否尝试在 background.js 或 content.js 中执行此操作,但如果是前者,您可以使用 webNavigation 事件执行此操作:
您需要在manifest.json中为webNavigation
设置权限:
"permissions": [
"webNavigation"
],
然后在background.js中:
chrome.webNavigation.onHistoryStateUpdated.addListener(function(details) {
console.log('Page uses History API and we heard a pushSate/replaceState.');
// do your thing
});
关于javascript - 从 chrome 扩展监控 history.pushstate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4646360/