Google Chrome DevTools Extension - Detect Page Change

我怕爱的太早我们不能终老 提交于 2019-12-07 18:25:42

问题


I am trying to detect when the webpage has changed from a Google Chrome DevTools Extension.

I currently have a devtools.html & devtools.js that detects if a condition is true and if it is, it adds the dev tool panel.

chrome.devtools.inspectedWindow.eval(/*my test*/, function (result, exception) {
    if ( exception === undefined && result === true ) {
        chrome.devtools.panels.create("My Panel", "", "panel.html", function (panel) {
            ...

The problem is, if I open up the dev tool, and then navigate to another page, it doesn't re-evaluate the condition and add the panel. I have to close and reopen the devtool again.

I think I could do this with a background page that I pass the tabId too, but not looked into how to do this yet, but I don't want to go down that route if there is a very simple technique I have overlooked.

Also, I have yet to find any information on Removing my panel once it has been created if the conditions were previously met, but no longer after a page navigation.


回答1:


Yes. I think you can use chrome.tabs.onUpdated instead. Sample code to detect the state changes can be:

chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
    if (changeInfo.status == 'complete') {
     }
});


来源:https://stackoverflow.com/questions/29698988/google-chrome-devtools-extension-detect-page-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!