最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome Extension : URL permission not working - Stack Overflow

programmeradmin2浏览0评论

We are using chrome webrequest API to intercept and modify headers on request. I was working fine until Chrome 72, but it's not working anymore. But when I replacing the permission with "<all_urls>" that's work. Also, I tried with another domain, Google, like this example : and that not working too.

Did you have any idea about why that not working anymore ? We will use "<all_urls>" for the moment but it's a huge permission that we do not really need.

manifest.json :

"permissions": [
 "webRequest",
 "webRequestBlocking",
 "*://*.merchantos/*"
 ]

background.js

  chrome.webRequest.onHeadersReceived.addListener(
    details => ({
      responseHeaders: filter(details.responseHeaders),
    }),
    { urls: ['*://*.merchantos/*'] },
    ['blocking', 'responseHeaders']
  )

EDIT :

Problem solved. For Chrome 72 you now need to add the host of the request into your permission to be able to edit headers.

manifest.json :

"permissions": [
 "webRequest",
 "webRequestBlocking",
 "*://*.merchantos/*",
 "*://*.mywebsite.coom/*/,
 ]

We are using chrome webrequest API to intercept and modify headers on request. I was working fine until Chrome 72, but it's not working anymore. But when I replacing the permission with "<all_urls>" that's work. Also, I tried with another domain, Google, like this example : https://developer.chrome./extensions/webRequest and that not working too.

Did you have any idea about why that not working anymore ? We will use "<all_urls>" for the moment but it's a huge permission that we do not really need.

manifest.json :

"permissions": [
 "webRequest",
 "webRequestBlocking",
 "*://*.merchantos./*"
 ]

background.js

  chrome.webRequest.onHeadersReceived.addListener(
    details => ({
      responseHeaders: filter(details.responseHeaders),
    }),
    { urls: ['*://*.merchantos./*'] },
    ['blocking', 'responseHeaders']
  )

EDIT :

Problem solved. For Chrome 72 you now need to add the host of the request into your permission to be able to edit headers.

manifest.json :

"permissions": [
 "webRequest",
 "webRequestBlocking",
 "*://*.merchantos./*",
 "*://*.mywebsite.coom/*/,
 ]
Share Improve this question edited Feb 5, 2019 at 1:32 Xeewi asked Jan 31, 2019 at 23:16 XeewiXeewi 391 silver badge7 bronze badges 2
  • 3 See the documentation for webRequest: to modify certain headers you need 'extraHeaders' now. – woxxom Commented Feb 1, 2019 at 4:17
  • Hi @wOxxOm , thanks for your answer. I tried to add this extras headers but that do not change anything :/ javascript chrome.webRequest.onHeadersReceived.addListener( details => ({ responseHeaders: filter(details.responseHeaders), }), { urls: ['*://*.merchantos./*'] }, ['blocking', 'responseHeaders', 'extraHeaders'] ) – Xeewi Commented Feb 4, 2019 at 14:45
Add a ment  | 

1 Answer 1

Reset to default 5

With Chrome 72, you need to specify both the target URL that you want to intercept, and the website URL from which the request is made in the permissions.

For example: https://www.mywebsite./ makes a request to https://abc.merchantos. which you want to intercept. Thus:

  • mywebsite. is making the request
  • abc.merchantos. is the target, which you would like to intercept
  • You have to specify both those URLs in your manifest.json:

    {
        ...
        "permissions": [
            "webRequest", 
            "webRequestBlocking",
            "*://*.mywebsite./*", 
            "*://*.merchantos./*"
        ],
        ...
    }
    
发布评论

评论列表(0)

  1. 暂无评论