Is it possible to catch requests from another extension?

北城以北 提交于 2019-12-12 01:52:55

问题


In my extension I use chrome.webRequest to catch requests from any web pages and it works like a charm.
But I can not catch any requests initialized from another extension. My manifest:

"permissions": [
    "tabs",
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
  ], 

background.js:

chrome.webRequest.onBeforeRequest.addListener(function (data) {
  console.log('catched', data);
}, {urls: ['<all_urls>']});

Tests:

  1. open tab with http://google.com:
    catched https://www.google.com/

  2. open extension console and run fetch('http://google.com'):
    catched http://google.com/

  3. open another extension console and run fetch('http://google.com'):
    // no output

Does anybody know if is it possible and if so, how to set it up? Thanks!


回答1:


Updated

My previous answer it not correct, see @Rob W's comments.

But when @Xan mentioned that extension URLs were visible to other extensions, it became apparent that this behavior is undesirable and a security issue, so I removed the ability for extensions to see other extensions' requests

Previous answer

It's not allowed to handle requests sent from other extensions.

In addition, even certain requests with URLs using one of the above schemes are hidden, e.g., chrome-extension://other_extension_id where other_extension_id is not the ID of the extension to handle the request, https://www.google.com/chrome, and others (this list is not complete).



来源:https://stackoverflow.com/questions/37926493/is-it-possible-to-catch-requests-from-another-extension

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