-
-
Notifications
You must be signed in to change notification settings - Fork 387
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
Open
nishu-murmu
wants to merge
13
commits into
wxt-dev:main
Choose a base branch
from
nishu-murmu:favicon-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+142
−1
Open
feat: Automatically update .wxt/types/paths.d.ts and web_accessible_resources manifest for favicon #1570
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f6080a5
feat: Automatically update .wxt/types/paths.d.ts and web_accessible_r…
nishu-murmu a698e88
fix: should augment the types for browser.runtime.getURL test fixed.
nishu-murmu 3370b3d
Merge branch 'main' of github.com:wxt-dev/wxt into favicon-types
nishu-murmu 918945d
fix: updating the name of the builtin modules for types related opera…
nishu-murmu 7493fdf
Merge branch 'main' of github.com:wxt-dev/wxt into favicon-types
nishu-murmu 7f706a9
fix: updating file name for specific use-case and reverting
nishu-murmu 3864cf3
chore: rename
nishu-murmu a883194
Merge branch 'main' of github.com:wxt-dev/wxt into favicon-types
nishu-murmu 6e44b81
Merge branch 'main' of github.com:wxt-dev/wxt into favicon-types
nishu-murmu efbc299
fix: adding docs and proper type for favicon and updating tests.
nishu-murmu f617b98
chore: updating docs.
nishu-murmu a983d27
chore: removing unused imports.
nishu-murmu d89074b
Merge branch 'main' into favicon-types
nishu-murmu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Favicons | ||
|
||
[Chrome Docs: How to fetch favicons](https://developer.chrome.com/docs/extensions/how-to/ui/favicons) | ||
|
||
#### What happens when you add favicons permissions in wxt.config.ts? | ||
|
||
WXT automatically adds value in `web_accessible_resources` with default value and updates the types for favicon. | ||
|
||
This is automatically added in manifest.json | ||
|
||
```js | ||
"web_accessible_resources": [ | ||
{ | ||
"resources": ["_favicon/*"], | ||
"matches": [], | ||
} | ||
] | ||
|
||
``` | ||
|
||
#### If you want to add custom values in `matches` parameter you can either add by hook or WXT modules. | ||
|
||
1. Via hook in wxt.config.ts | ||
|
||
```js | ||
|
||
import { defineConfig } from "wxt"; | ||
// See https://wxt.dev/api/config.html | ||
export default defineConfig({ | ||
modules: ["@wxt-dev/module-react"], | ||
hooks: { | ||
"build:manifestGenerated": (_, manifest) => { | ||
const favicon_resource: any = manifest.web_accessible_resources?.find( | ||
(resource: any) => resource.includes("favicon") | ||
); | ||
favicon_resource.matches?.push("<all_urls>"); | ||
manifest.web_accessible_resources ??= []; | ||
manifest.web_accessible_resources?.push(favicon_resource); | ||
}, | ||
}, | ||
}); | ||
|
||
``` | ||
|
||
2. Via custom module | ||
|
||
- Follow the guide for [creating modules](https://wxt.dev/guide/essentials/wxt-modules.html#writing-modules) and paste this below code. | ||
|
||
```js | ||
|
||
import { defineWxtModule } from "wxt/modules"; | ||
|
||
export default defineWxtModule({ | ||
setup(wxt) { | ||
wxt.hooks.hook("build:manifestGenerated", (_, manifest) => { | ||
const favicon_resource: any = manifest.web_accessible_resources?.find( | ||
(resource: any) => resource.includes("favicon") | ||
); | ||
favicon_resource.matches?.push("<all_urls>"); | ||
manifest.web_accessible_resources ??= []; | ||
manifest.web_accessible_resources?.push(favicon_resource); | ||
}); | ||
}, | ||
}); | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { defineWxtModule } from '../modules'; | ||
|
||
export default defineWxtModule({ | ||
name: 'wxt:built-in:favicon-permission', | ||
setup(wxt) { | ||
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 commentThe 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 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', ...)
},
}) |
||
const favicon_resource: any = { | ||
resources: ['/_favicon/*'], | ||
matches: [], | ||
}; | ||
manifest.web_accessible_resources ??= []; | ||
manifest.web_accessible_resources?.push(favicon_resource); | ||
}); | ||
} | ||
}); | ||
}, | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { WxtModule } from '../types'; | ||
import unimport from './unimport'; | ||
import faviconPermission from './favicon-permission'; | ||
|
||
export const builtinModules: WxtModule<any>[] = [unimport]; | ||
export const builtinModules: WxtModule<any>[] = [unimport, faviconPermission]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.