Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
209 views
in Technique[技术] by (71.8m points)

angular - Chrome extension: Setup communication between init script and panel.html/js

I'm trying to build a chrome extension and add a panel to devtools. The ultimate goal is to run an angular app in that panel and monitor network traffic. Anyway, my manifest looks like this

{
  "name": "Great Example",
  "version": "1.0",
  "description": "Build an Extension with Angular",
  "manifest_version": 2,
  "permissions": [
    "debugger",
    "activeTab",
    "webNavigation",
    "storage",
    "webRequest",
    "*://*/*"
  ],
  "devtools_page": "./devtools/setup.html"
}

and ./devtools/setup.html:

<html>
    <head></head>

    <body>
        <script src="setup.js"></script>
    </body>
</html>

and setup.js

chrome.devtools.panels.create("My Panel",
    "../assets/images/logo.png",
    "../index.html",
    function(panel) { ... }
);

And ../index.html is my angular app. So far I managed see have my panel in DevTools showing my angular app. Now my next step is, for example, to list all XHR calls in my angular app.

I tried the following code in the ngOnInit of AppComponent:

ngOnInit(): void {
  chrome.webRequest.onCompleted.addListener((details) => {
    this.test = 'ok';
  }, { urls: ['*://*/*'] });
}

In my template I render test but it never shows ok so I guess onCompleted never goes off. So maybe this code should run in that other file (setup.js) and communicate back to my app in a different way. I'm a bit lost here so any suggestions to fix this are very welcome?

question from:https://stackoverflow.com/questions/65843290/chrome-extension-setup-communication-between-init-script-and-panel-html-js

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...