feat: Automatically update .wxt/types/paths.d.ts and web_accessible_resources manifest for favicon#1570
feat: Automatically update .wxt/types/paths.d.ts and web_accessible_resources manifest for favicon#1570nishu-murmu wants to merge 13 commits intowxt-dev:mainfrom
Conversation
…esources manifest for favicon
✅ Deploy Preview for creative-fairy-df92c4 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@aklinker1 |
|
@aklinker1 |
There was a problem hiding this comment.
Thanks for adding the test! After seeing the expected outupt, I think this PR is still missing a few things:
- The favicon's URL needs to be typed as
"/_favicon?${string}", right? Or else query parameters won't be allowed. - The
web_accessible_resources.matchesis an empty array, meaning I would have to write a module or hook to modify that array so I can load favicons from content scripts. A simpler solution would be to not add this entry if one containing the/_faviconURL already exists. That way devs can just add their own entry and not worry about duplicating them. - I think we need to add docs around this similar to the https://wxt.dev/guide/essentials/scripting.html page, just documenting what happens when you add the
faviconpermission, how to fetch a favicon, and how to add a custommatchesto theweb_accessible_resourcesentry.
In second point, so basically only types will be updated automatically and |
There was a problem hiding this comment.
A couple of follow-up changes, but it looks good overall! Thanks for working on this one.
In second point, so basically only types will be updated automatically and web_accessible_resources will be added by devs?
Yes. Not every extension that uses the favicon permission needs a web_acccessible_resources entry added - you only need that to use favicons in content scripts. If someone needs access to favicons in a content script, they should add the entry themselves.
So we should just remove the second hook from the module.
| await project.prepare({ | ||
| manifest: { | ||
| permissions: ['favicon'], | ||
| }, | ||
| }); | ||
|
|
||
| await project.build({ | ||
| manifest: { | ||
| permissions: ['favicon'], | ||
| }, | ||
| }); |
There was a problem hiding this comment.
Build will run prepare automatically, you don't need to include both.
| await project.prepare({ | |
| manifest: { | |
| permissions: ['favicon'], | |
| }, | |
| }); | |
| await project.build({ | |
| manifest: { | |
| permissions: ['favicon'], | |
| }, | |
| }); | |
| await project.build({ | |
| manifest: { | |
| permissions: ['favicon'], | |
| }, | |
| }); |
| wxt.hooks.hook('prepare:publicPaths', async (wxt, paths) => { | ||
| if (wxt.config.manifest.permissions?.includes('favicon')) { | ||
| paths.push('_favicon/?${string}'); | ||
| wxt.hooks.hook('build:manifestGenerated', (_, manifest) => { |
There was a problem hiding this comment.
Edit: See review comment, we can probably just delete the second hook. Keeping the original comment here just to explain how modules should be written
The second hook should be added inside the setup function, not nested inside the first hook's callback:
export default defineWxtModule({
name: 'wxt:built-in:favicon-permission',
setup(wxt) {
const hasManifestPermission = () => wxt.config.manifest.permissions?.includes('favicon')
wxt.hooks.hook('prepare:publicPaths', ...)
wxt.hooks.hook('build:manifestGenerated', ...)
},
})
Overview
As suggested I've used WxtModules to implement this functionality.
Manual Testing
Related Issue
This PR closes #1559