-
-
Notifications
You must be signed in to change notification settings - Fork 375
feat: Automatically update .wxt/types/paths.d.ts and web_accessible_resources manifest for favicon #1570
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
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.matches
is 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/_favicon
URL 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
favicon
permission, how to fetch a favicon, and how to add a custommatches
to theweb_accessible_resources
entry.
In second point, so basically only types will be updated automatically and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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