Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling patternToRegex on <all_urls> should match about:srcdoc #13

Closed
twschiller opened this issue Jan 9, 2024 · 6 comments
Closed

Comments

@twschiller
Copy link

Report

Related

@fregante
Copy link
Owner

fregante commented Jan 9, 2024

It's a bit complicated because about:srcdoc and data: URLs are not allowed in the manifest and Chrome doesn't inject the content scripts into them if they're the top frame:

https://stackoverflow.com/a/31052496

data:text/html,%3Ch1%3EHello%2C%20World%21%3C%2Fh1%3E
Screenshot

So there's a varying degree of support for these protocols, depending on where they're used.

I might add support for it via option, but for the issue at hand, you can probably inline a specific check on this line for now until I figure out what to do:

https://github.com/pixiebrix/pixiebrix-extension/blob/d39b94c3dc52f8f29b6340e22b30101d10be1c7b/src/bricks/available.ts#L31

@fregante
Copy link
Owner

fregante commented Jan 9, 2024

More context in the source:

https://chromium.googlesource.com/chromium/src/+/refs/heads/main/extensions/common/url_pattern.cc#31

No mentions of srcdoc found :(

@twschiller
Copy link
Author

I agree that it would need to be behind and option/in a different method.

I might add support for it via option, but for the issue at hand, you can probably inline a specific check on this line for now until I figure out what to do:

👍

@fregante
Copy link
Owner

fregante commented Apr 6, 2024

As specified in pixiebrix/pixiebrix-extension#8170, about:srcdoc is not something the browser actually matches patterns against.

From this API's standpoint:

  • does about:srcdoc match <all_urls>? No

@fregante fregante closed this as not planned Won't fix, can't repro, duplicate, stale Apr 6, 2024
@fregante
Copy link
Owner

fregante commented Apr 6, 2024

However:

  • does <all_urls> inject into about:srcdoc? Yes if the parent is not chrome-extension://
  • does *://*/* inject into about:srcdoc? Yes if the parent is not chrome-extension://
  • does anything else inject into about:srcdoc? Maybe, undeterminable

Ideally you should follow the browser and never match about:srcdoc:

if (location.href === 'about:srcdoc') {
  return pattern.matches(window.parent.location.href); // Parent URL
} else {
  return pattern.matches(location.href);
}

You can take shortcuts to this depending on what you want to do next. Since <all_urls> and *://*/* are equivalent in this scenario, the function can be:

function shouldBrickRunHere(pattern) {
  //     100% certainty                    probably 🤞                 probably 🤞 
  return pattern.matches(location.href) || pattern === `<all_urls>` || pattern ===  `*://*/*`;
}

@fregante
Copy link
Owner

fregante commented Apr 6, 2024

From an extension architecture standpoint, I believe iframes should be dependents/puppets of the main frame and should not run anything independently, but this is much harder to achieve.

@fregante fregante changed the title Calling patternToRegex on <all_urls> should match srcdoc: Calling patternToRegex on <all_urls> should match about:srcdoc Apr 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants