How to dynamically load images in chrome extension v3 if images are not known in advance? - Stack Overflow

I know resources that are known in advance should be bundled with the chrome extension and exposed with

I know resources that are known in advance should be bundled with the chrome extension and exposed with web_accessible_resources, but what about images that are not known in advance and therefore cannot be included in the bundle?

I'm upgrading chrome v2 to v3. In v2, I used the background script to add my domain to the CSP and then used the content script to inject a script tag to my domain (i.e. <script src='my_website'). For v3, the CSP cannot be dynamically overridden. I've found solutions for css, and js, but not for loading images that are not known in advance.

I have a web app where people sign up and add a profile pic, and then use the extension to do stuff on web pages and I want to show the profile pics of people who have interacted with the page. Currently, I use the content script to inject a script tag into the page that loads the script from the bundled extension, which is a react app that displays <img> tags with the src attribute, which no longer works.

Is there any solution for this?

I know resources that are known in advance should be bundled with the chrome extension and exposed with web_accessible_resources, but what about images that are not known in advance and therefore cannot be included in the bundle?

I'm upgrading chrome v2 to v3. In v2, I used the background script to add my domain to the CSP and then used the content script to inject a script tag to my domain (i.e. <script src='my_website'). For v3, the CSP cannot be dynamically overridden. I've found solutions for css, and js, but not for loading images that are not known in advance.

I have a web app where people sign up and add a profile pic, and then use the extension to do stuff on web pages and I want to show the profile pics of people who have interacted with the page. Currently, I use the content script to inject a script tag into the page that loads the script from the bundled extension, which is a react app that displays <img> tags with the src attribute, which no longer works.

Is there any solution for this?

Share Improve this question asked Mar 24 at 2:14 JustCodinJustCodin 797 bronze badges 3
  • It will be possible in the future when DNR implements regex replacement in response headers. Right now you can strip CSP entirely or use data: URI for the images, which is allowed on most sites. – woxxom Commented Mar 24 at 5:32
  • I'm currently using data uri, which does generally work, but hoped for a true solution that worked in all cases. Do you know if there's any ETA on DNR to implement regex replacement. Chrome approval process likely wouldn't approve removed csp, but curious, how would you strip the CSP? Also, just wanted to say thanks, @woxxom, for your help in the chrome extension community. – JustCodin Commented Mar 25 at 0:23
  • See this example. – woxxom Commented Mar 25 at 0:28
Add a comment  | 

1 Answer 1

Reset to default 0

You can use wildcard for all expected image extensions and/or all files with "*"


  "web_accessible_resources": [
    {
      "resources": [
        "*.jpg",
        "*.png",
        "*.webp",
        "*.svg",
        "*"
      ],
      "matches": [
        "<all_urls>"
      ],
      "extensions": []
    }
  ],

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744263600a4565756.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信