0

I'd like to use the popup of an extension to set settings that make changes on about:blank pages html one is on (from Google Slide Presenter in a separate tab), in terms of how the extension is supposed to behave on that page.

As far I understood I need to use content_scripts due to about:blank which requires "match_about_blank" : true as otherwise I have not way to run javascript on that page via the extension, unless there is a way using executeScript?

Is it possible from within the popup to access the HTML of that open tab using content_script?

I.e. I'd like to retrieve the tabs page title, i.e. using document.title or extract from the HTML. Also with Javascript I'd like to change some of the content within a div.

The only workaround I can think of, unless its the only way, is to run javascript on the page to extract and store the value (chrome.storage.sync.set) so I can retrieve it in the popup with javascript (chrome.storage.sync.get).

Wondering if there is a better way directly and also how to change content in the tab i.e. by clicking a button in the popup (maybe via event listener on the tab and a push from the popup?).

I already tried the answer using chrome.scripting.executeScript. with Manifest v3 but couldn't make it work. How to access the webpage DOM/HTML from an extension popup or background script?

Markus
  • 458
  • 4
  • 16
  • Depending on how exactly this tab was opened (created) there may be no solution. The `match_about_blank` is about a different thing (an iframe without src), its name is just misleading. – wOxxOm Nov 04 '22 at 21:06
  • Can you try it please? Open a google Slide and launch presenter view in a tab (on Windows start Presenter view > right click on window > Show as tab, on Mac open Slide in a fullscreen browser and then launch Presenter view). It will show as about:blank page. You helped me previously for this https://stackoverflow.com/q/74237964/8719001 (I need to update it with the current code I run now that works) Didn't think this is an iframe but an internal page, if I understand correctly. – Markus Nov 05 '22 at 11:14
  • Its real URL is different and you can see it by opening devtools for this window. – wOxxOm Nov 05 '22 at 11:39
  • Thanks, where do you see the real URL? I couldn't find it, is it in the Application tab? I saw some references to docs.google.com*** where the slide is hosted and presenter view launched from. How would you recommend launching javascript via extension to change content on that presenter view tab, especially from the extension popup window for easier direct use i.e. click a button or enter value in a field to change content in the tab html? Thanks @wOxxOm – Markus Nov 05 '22 at 18:39
  • 1
    It's in the title of devtools when it's detached, otherwise just run `location` in the console. Once you get the URL you can target this window using chrome.tabs.query + chrome.scripting.executeScript or you can use `content_scripts`, it's up to you. – wOxxOm Nov 05 '22 at 20:58
  • Thanks @wOxxOm, I think I understand it a bit better now, the `content_script` is different approach being declarative as opposed to the programmatic that you demonstrated in your example. In other words I can't be using your example number 2 within content_scripts, correct? https://stackoverflow.com/a/67227376/8719001 I will try again if I can use JS without `content_script` on this page as I think it would be easier not requiring the use of messaging to change DOM elements which `content_script` requires. – Markus Nov 06 '22 at 15:13

0 Answers0