Script content does not work in iframe on another extension page

Suppose Google Chrome has 2 extensions installed.


The 1st extension launches content.js on w3.org:

manifest.json:

"content_scripts": [{ "matches": [ "https://www.w3.org/*" ], "all_frames": true, "js": [ "content.js" ] }] 

content.js:

 alert('content'); 

The second extension has page.html, which loads w3.org in an iframe:

manifest.json:

 "web_accessible_resources": ["page.html"] 

page.html:

 <!DOCTYPE html> <iframe src="https://www.w3.org/"></iframe> 

Now enter the address bar chrome-extension://2nd-extension-id/page.html . You will see w3.com, but content.js has not been started (no alert() ). I do not see errors in the console.

Question: how to allow script content to run in this iframe?


I created a Chrome issue . Status: WontFix, unfortunately. But this may be changed in the future ...

+5
source share
1 answer

You cannot with extensions, but you can do something similar in Google Apps: you can use webview instead of iframe. Therefore, you can enter the script through the executeScript method.

-1
source

Source: https://habr.com/ru/post/1244837/


All Articles