0

I am working on Chrome extension allowing to get DOM elements attributes by clicking on it. But the extension does not work on some web-pages or for certain elements. E.g.:

Scenario 1: 1.1. Open Google page by entering google.com URL in address field. 1.2. Click on any element. 1.3. The script works as expected.

Scenario 2: 2.1 Open new browser tab. 2.2. New Google page is open (as it is default page) and its address string is blank. 2.3. Click on any element. 2.4. The script does not work, no alert popup appears

I suppose that the browser opens cached page by default, but anyway the script should work as DOM elements exist.

Also I have the same problem on another page where the script works for some elements and does not work for the auto generated elements located on this page. What is the reason of not working script?

enter image description here

enter image description here

vitaliy4us
  • 483
  • 5
  • 21
  • The onclick property isn't the problem because content scripts run in isolated environment. The problem is that the new [empty] browser tab is a built-in browser page which has an internal URL `chrome://newtab` so extensions can't run content scripts there by default, see [Can you access chrome:// pages from an extension?](https://stackoverflow.com/q/19042857) – wOxxOm Jul 19 '20 at 09:52
  • Thank you @wOxxOm, using the link providing by you I have some progress, but the issue was not comletely solved. I added the flag `chrome://flags/#extensions-on-chrome-urls` in my chrome settings and the new value `"chrome://*/*" ` to `matches` parameter. So now the script works for some chrome://* pages, e.g. `chrome://extensions` but not the same for the empty `chrome://newtab` page. But actually this is not a real problem for me. It is much more important to have access to the automaticaly generated elements. Have you any idea regarding this sort of problem? – vitaliy4us Jul 19 '20 at 11:20
  • The real contents of newtab page is inside an iframe so you need `"all_frames":true` in manifest, which will make your content script run in *every* iframe. See also [Is there a JavaScript / jQuery DOM change listener?](https://stackoverflow.com/a/39508954) – wOxxOm Jul 19 '20 at 11:40

0 Answers0