0

I'm building a chrome extension and that includes the following scenario in order to achieve my goal.

  • I want to send info from devtools.js to content script even the DevTools is close or not open. Is it possible?! Because in the documentation, devtools.html or any script attached to it are called or executed when the DevTools is opened.
  • How to access Console Tab, Network Tab and other tabs then pass the information to the content script?

Is there a way to achieve these two points?

  • 1) No. When devtools is closed your devtools.js doesn't run. 2) Define "access". – wOxxOm Sep 09 '21 at 19:50
  • Thanks for your feedback @wOxxOm what do you mean by "Define access"? – Muhammad Yusuf Cabais Sep 09 '21 at 19:55
  • what i mean in #2 is, for example i call console.log('Info') some where in my code, then how can i get the text 'Info' from my content script? – Muhammad Yusuf Cabais Sep 09 '21 at 20:06
  • There's no special method to access panels so you'll have to use [normal messaging](https://developer.chrome.com/extensions/messaging). – wOxxOm Sep 10 '21 at 05:55
  • Thanks for your reply @kylec i appreciate it. But my question is can I use that devtools extention API even i didn’t open the chrome devtools itself? For example I want to pass the data output using console.log to content script and display it in the page. How can I achieve that? – Muhammad Yusuf Cabais Sep 11 '21 at 07:47
  • Just to give more example: Example a user installed my extension, then he is developing some web application and he run a console.log() somewhere in his/her code, then that result log, how can I catch that and display in the script that i injected. basically when we console.log a variable in our code we open that devtools and see that log. But here i want to display the output log in the screen when the pages is loaded. I hope it make sense. Thanks in advance, – Muhammad Yusuf Cabais Sep 11 '21 at 07:47
  • You can use `chrome.debugger` API to intercept console messages but it'll show a warning in all tabs so a better solution is to hook `console.log` function in [page context](/a/9517879) e.g. replace it without own that remembers the arguments in storage and calls the original function. – wOxxOm Sep 11 '21 at 08:14
  • Thanks @wOxOm i will really appreciate if you can create a boilerplate example and add as an Answer so another can benefit as well! Thanks in advance... – Muhammad Yusuf Cabais Sep 11 '21 at 08:33
  • There are existing answers, try searching for these terms e.g. `hooking page functions in extension content script`. – wOxxOm Sep 11 '21 at 08:37
  • i did my research also but most of the extensions are using popup page or panel. like redux and react dev tools. Therefore DevTools was still opened. My i idea is different. im not sure if it is possible... – Muhammad Yusuf Cabais Sep 11 '21 at 08:41
  • It's possible and googling the terms I suggested in my comment above gives an answer in the top result. – wOxxOm Sep 11 '21 at 08:47

0 Answers0