2

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.

2 Answers 2

3

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') { } }); 
Sign up to request clarification or add additional context in comments.

5 Comments

chrome.tabs is undefined on the devtools page. Even if I have "permissions": ["tabs"], in the manifest.
chrome.tabs is only available in background scripts and popup scripts.
You are 100% correct, So I wonder why you suggested this when you knew I was after a suggestion that did not involve the background?
I thought you mentioned you wonder how to do it with a background page in your question.
Sorry, I re-read how I wrote it, I can kinda see how it could sound, it is mostly the "trying to look for another way". I am guessing there is not. I'l upvote for your help, but I'l wait to see if there are any more responses for accepted answer.
2

https://developer.chrome.com/extensions/devtools_network#event-onNavigated

chrome.devtools.network.onNavigated.addListener( function(requesturl) { console.log('Navigating toooooo: ' + requesturl); }); 

1 Comment

I was doing it on is mega old project and not using it anymore, but it to me looks like it should work. So you get the check mark..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.