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

WebExtension shouldn't rename options.html #8130

Closed
TiagoCavalcante opened this issue May 23, 2022 · 8 comments
Closed

WebExtension shouldn't rename options.html #8130

TiagoCavalcante opened this issue May 23, 2022 · 8 comments
Labels

Comments

@TiagoCavalcante
Copy link

🙋 feature request

@parcel/config-webextension shouldn't rename the file options.html when it is mentioned inside the manifest.

🤔 Expected Behavior

The file options.html should keep it name in the dist folder.

😯 Current Behavior

This file (as any other file) have its name changed, in this case to options.COMMIT_SHA.html.

💁 Possible Solution

Don't rename the file from the field options_ui.page (inside manifest.json).

🔦 Context

Many extensions have some way to open that file from JS, and the mangling make that inviable/impossible as the majority of the extensions support multiple browsers, and each browser have its own options.html.

💻 Examples

The extension I was porting to Parcel uses the following code to open the options page:

window.open("/options.html", "_blank");
@101arrowz
Copy link
Member

Hashing used to be disabled for every asset in web extensions but it caused a lot of issues with collisions, so we changed it. For options pages, you should definitely not need a static file name to open the page because you can simply do chrome.runtime.openOptionsPage() (or browser.runtime.openOptionsPage() on Firefox, etc.). If you actually need the URL for some reason, you can do the following:

import optionsPage from 'url:./path/to/options.html';

// Do anything with the URL, e.g. open it
window.open(optionsPage, "_blank");

@filips123
Copy link

Would it be possible to add some option to disable hashing (revert to previous behaviour)? It's a bit annoying having to "import" URL for such assets. Also, I have a page that is accessible both from browser action popup and normal tab, so it would be nicer if the user sees the original/unhashed URL.

@101arrowz
Copy link
Member

101arrowz commented May 29, 2022

It's actually probably for the best you have to import the URL because that is more robust against changes to the asset type, Parcel config, etc.

I have a page that is accessible both from browser action popup and normal tab, so it would be nicer if the user sees the original/unhashed URL

Don't extensions already show the massive, ugly extension ID before the file name? If you really need this it is possible by making a custom namer plugin. This also makes it possible to just use the original locations as URLs without importing them (though I do not recommend this).

@fregante
Copy link
Contributor

fregante commented Jun 29, 2022

openOptionsPage is definitely the correct way to open the options page. However for complex extensions you might still have multiple html pages or hash-based routing, so you really need to open options.html#/advanced

Unless window.open('foo.html') is already supported by a standard Parcel build, it should not be supported for extensions either. But if it is, then maybe *.tabs.create({url}) might have to be supported too:

In any case I feel that generally HTML pages should not be renamed though as they’re an app’s entry points:

@TiagoCavalcante
Copy link
Author

@fregante I forgot to say, I found a universal (and kinda obivious) way to do this:

// @ts-expect-error: Parcel allow this
import optionsPage from "./options.html"
window.open(optionsPage, "_blank")

@fregante
Copy link
Contributor

Can you reopen the issue? This is still true:

WebExtension shouldn't rename options.html

@fregante
Copy link
Contributor

fregante commented Aug 18, 2022

By the way, if you want to preserve some filenames, you can specify them as web_accessible_resources:

  "web_accessible_resources": ["options.html"]

even as globs, like:

  "web_accessible_resources": ["*.html"]

or

  "web_accessible_resources": ["**/*.html"]

This has the obvious drawback that the files are now publicly available to the websites that your users visit.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

@github-actions github-actions bot added the Stale Inactive issues label Feb 15, 2023
@github-actions github-actions bot closed this as completed Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants