Skip to content

Commit

Permalink
AI review and typo fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Oct 1, 2024
1 parent 4d7b5db commit dee9511
Show file tree
Hide file tree
Showing 28 changed files with 65 additions and 77 deletions.
9 changes: 0 additions & 9 deletions docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,6 @@ export default defineConfig({
menuItem('How WXT Works', 'how-wxt-works.md'),
]),
]),
'/i18n/': menuRoot([
menuGroup('@wxt-dev/i18n', '/i18n/', [
menuItem('Introduction', 'introduction.md'),
menuItem('Installation', 'installation.md'),
menuItem('Messages File Format', 'messages-file-format.md'),
menuItem('Build Integrations', 'build-integrations.md'),
menuItem('Editor Support', 'editor-support.md'),
]),
]),
'/api/': menuRoot([
menuGroup(
'CLI Reference',
Expand Down
6 changes: 4 additions & 2 deletions docs/guide/essentials/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ img.src = imageUrl;

## Inside Content Scripts

Assets inside content scripts are a little different. By default, when you import an asset, it returns just the path to the asset. This is because WXT assumes you're loading assets from the same hostname.
Assets inside content scripts are a little different. By default, when you import an asset, it returns just the path to the asset. This is because Vite assumes you're loading assets from the same hostname.

But, inside content scripts, the hostname is whatever the tab is set to. So if you try to fetch the asset, manually or as an `<img>`'s `src`, it will be loaded from the tab's website, not your extension.

Expand All @@ -77,4 +77,6 @@ export default defineContentScript({

## WASM

TODO
:::warning 🚧 Under construction
These docs will be coming soon!
:::
19 changes: 3 additions & 16 deletions docs/guide/essentials/config/browser-startup.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ During development WXT uses [`web-ext` by Mozilla](https://www.npmjs.com/package

You can configure browser startup in 3 places:

1. `<rootDir>/web-ext.config.ts`: Ignored from version control, this file lets you configure your own options without effectint other developers
1. `<rootDir>/web-ext.config.ts`: Ignored from version control, this file lets you configure your own options without affecting other developers

```ts
import { defineRunnerConfig } from 'wxt';
Expand Down Expand Up @@ -49,26 +49,13 @@ Right now, Chromium based browsers are the only browsers that support overriding

To persist data, set the `--user-data-dir` flag:

:::code-group

```ts [Mac/Linux]
```ts
export default defineRunnerConfig({
chromiumArgs: ['--user-data-dir=./.wxt/chrome-data'],
});
```

```ts [Windows]
// WARNING: This doesn't seem to work on windows, chrome doesn't respect the
// --user-data-dir. If you figure out a way to do this, please share so we can
// update these docs.
export default defineRunnerConfig({
chromiumArgs: ['--user-data-dir=.\\.wxt\\chrome-data'],
});
```

:::

Now, next timne you run the `dev` script, a persistent profile will be created in `.wxt/chrome-data/{profile-name}`. With a persistent profile, you can install devtools extensions to help with development, allow the browser to remember logins, etc, without worrying about the profile being reset the next time you run the `dev` script.
Now, next time you run the `dev` script, a persistent profile will be created in `.wxt/chrome-data/{profile-name}`. With a persistent profile, you can install devtools extensions to help with development, allow the browser to remember logins, etc, without worrying about the profile being reset the next time you run the `dev` script.

### Disable Opening Browser

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/essentials/config/entrypoint-loaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Ignoring WXT itself (it's added automatically for you), there are three packages

## jiti

The original method WXT used to import TS files. However, because it doesn't support vite plugins like `vite-node`, there is one main caveot to it's usage: **_module side-effects_**.
The original method WXT used to import TS files. However, because it doesn't support vite plugins like `vite-node`, there is one main caveat to its usage: **_module side-effects_**.

To enable `jiti`:

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/essentials/config/hooks.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hooks

WXT includes an in-depth system that let's you hook into the build process and make changes.
WXT includes an in-depth system that lets you hook into the build process and make changes.

Here's an example hook that modifies the `manifest.json` file before it is written to the output directory:

Expand All @@ -17,6 +17,6 @@ export default defineConfig({
});
```

> Most hooks provide the `wxt` object as the first argument. If contains the resolved config and other info about the current build.
> Most hooks provide the `wxt` object as the first argument. It contains the resolved config and other info about the current build.
Putting one-off hooks like this in your config file is simple, but if you find yourself writing lots of hooks, you should extract them into [WXT Modules](/guide/essentials/wxt-modules) instead.
8 changes: 4 additions & 4 deletions docs/guide/essentials/config/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

In WXT, there is no `manifest.json` file in your source code. Instead, WXT generates it during the build process based off files in your project.

## Manfiest Config
## Manifest Config

To manually add a property to the `manifest.json` output during builds, use the `manifest` config inside `wxt.config.ts`:

Expand All @@ -28,7 +28,7 @@ export default defineConfig({

### MV2 and MV3 Compatibility

When adding properties to the manifest, always define the property in it's MV3 format when possible. When targetting MV2, WXT will automatically convert these properties to their MV2 format.
When adding properties to the manifest, always define the property in it's MV3 format when possible. When targeting MV2, WXT will automatically convert these properties to their MV2 format.

For example, for this config:

Expand Down Expand Up @@ -81,7 +81,7 @@ WXT will generate the following manifests:

:::

You can also specify properties specific to a single manifest version, and they will be stripped out when targetting the other manifest version.
You can also specify properties specific to a single manifest version, and they will be stripped out when targeting the other manifest version.

## Name

Expand Down Expand Up @@ -207,7 +207,7 @@ export default defineConfig({

In MV2, you have two options: [`browser_action`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_action) and [`page_action`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/page_action). In MV3, they were merged into a single [`action`](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/action) API.

By default, whenever an `action` is generated, WXT falls back to `browser_action` when targetting MV2.
By default, whenever an `action` is generated, WXT falls back to `browser_action` when targeting MV2.

### Action With Popup

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/essentials/config/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineAppConfig({
```

:::warning
This file is commited to the repo, so don't put any secrets here. Instead, use [Environment Variables](#environment-variables)
This file is committed to the repo, so don't put any secrets here. Instead, use [Environment Variables](#environment-variables)
:::

To access runtime config, WXT provides the `useAppConfig` function:
Expand Down Expand Up @@ -75,5 +75,5 @@ export default defineAppConfig({
This has several advantages:

- Define what environment variables are use at runtime in a single file
- Convert strings to nicer type, like booleans or arrays
- Convert strings to nicer types, like booleans or arrays
- Provide default values if an environment variable is not provided
2 changes: 1 addition & 1 deletion docs/guide/essentials/config/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ To specify custom compiler options, add them in `<rootDir>/tsconfig.json`:
{
"extends": ".wxt/tsconfig.json",
"compilerOptions": {
"jsx": "perserve",
"jsx": "preserve/",
},
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/essentials/config/vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

WXT uses [Vite](https://vitejs.dev/) under the hood to bundle your extension. As such, all of [Vite's features](https://vitejs.dev/guide/features.html) are available when using WXT.

WXT orchastrates several different Vite builds to bundle your extension. For more info, read [How WXT Works](/guide/resources/how-wxt-works).
WXT orchestrates several different Vite builds to bundle your extension. For more info, read [How WXT Works](/guide/resources/how-wxt-works).

## Change Vite Config

Expand Down
12 changes: 6 additions & 6 deletions docs/guide/essentials/content-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default defineContentScript({
});
```

This object is responsible for tracking whether or not the content script's context is "invalidated". Most browsers, by default, do not stop content scripts if the extension is uninstalled, updated, or disabled. When this happens, content scripts start reproting this error:
This object is responsible for tracking whether or not the content script's context is "invalidated". Most browsers, by default, do not stop content scripts if the extension is uninstalled, updated, or disabled. When this happens, content scripts start reporting this error:

```
Error: Extension context invalidated.
Expand Down Expand Up @@ -73,7 +73,7 @@ export default defineContentScript({
To create a standalone content script that only includes a CSS file:

1. Create the CSS file: `entrypoints/example.content.css`
2. Use the `build:manfiestGenerated` hook to add the content script to the manifest:
2. Use the `build:manifestGenerated` hook to add the content script to the manifest:
```ts
// wxt.config.ts
export default defineConfig({
Expand Down Expand Up @@ -456,7 +456,7 @@ If you don't need to run your UI in the same frame as the content script, you ca
WXT provides a helper function, [`createIframeUi`](/api/reference/wxt/client/functions/createIframeUi), which simplifies setting up the IFrame.
1. Create an HTML page that will be loaded into your IFrame
1. Create an HTML page that will be loaded into your IFrame:
```html
<!-- entrypoints/example-iframe.html -->
<!doctype html>
Expand All @@ -471,7 +471,7 @@ WXT provides a helper function, [`createIframeUi`](/api/reference/wxt/client/fun
</body>
</html>
```
1. Add the page to the manifest's `web_accessible_resources`
1. Add the page to the manifest's `web_accessible_resources`:
```ts
// wxt.config.ts
export default defineConfig({
Expand All @@ -485,7 +485,7 @@ WXT provides a helper function, [`createIframeUi`](/api/reference/wxt/client/fun
},
});
```
1. Create and mount the IFrame
1. Create and mount the IFrame:
```ts
export default defineContentScript({
Expand Down Expand Up @@ -523,7 +523,7 @@ export default defineContentScript({
});
```
However, this approach has several notible drawbacks:
However, this approach has several notable drawbacks:
- Doesn't support MV2
- `world: "MAIN"` is only supported by Chromium browsers
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/essentials/entrypoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ For web extensions, there are two types of entrypoints:
- **Listed**: Referenced in the `manifest.json`
- **Unlisted**: Not referenced in the `manifest.json`

Throughout the rest of WXT's documentation, listed files are refered to by name. For example:
Throughout the rest of WXT's documentation, listed files are referred to by name. For example:

- Popup
- Options
Expand Down
6 changes: 3 additions & 3 deletions docs/guide/essentials/frontend-frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default defineConfig({
## Multiple Apps

Since web extensions usually contain multiple UIs accross multiple entrypoints (popup, options, changelog, side panel, content scripts, etc), you'll need to create individual app instances, one per entyrypoint.
Since web extensions usually contain multiple UIs across multiple entrypoints (popup, options, changelog, side panel, content scripts, etc), you'll need to create individual app instances, one per entrypoint.

Usually, this means each entrypoint should be a directory with it's own files inside it. Here's the recommended folder structure:

Expand All @@ -85,15 +85,15 @@ Usually, this means each entrypoint should be a directory with it's own files in
📄 index.html
📄 App.tsx
📄 main.tsx <--------- Create and mount your app here
📄 style.css <--------- Have entrypoint-specific styles to apply?
📄 style.css <--------- Entrypoint-specific styles
📄 router.ts
```

## Configuring Routers

All frameworks come with routers for building a multi-page app using the URL's path... But web extensions don't work like this. Since HTML files are static, `chrome-extension://{id}/popup.html`, there's no way to change the entire path for routing.
Instead, you need to configure the router to run in "hash" mode, where the routing information is apart of the URL's hash, not the path (ie: `popup.html#/` and `popup.html#/account/settings`).
Instead, you need to configure the router to run in "hash" mode, where the routing information is a part of the URL's hash, not the path (ie: `popup.html#/` and `popup.html#/account/settings`).

Refer to your router's docs for information about hash mode and how to enable it. Here's a non-extensive list of a few popular routers:

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/essentials/i18n.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# I18n

[Chrome Docs](https://developer.chrome.com/docs/extensions/develop/concepts/messaging)[Firefox Docs](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#communicating_with_background_scripts)
[Chrome Docs](https://developer.chrome.com/docs/extensions/reference/api/i18n)[Firefox Docs](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/i18n)

This page discusses how to setup internationalization using the vanilla `browser.i18n` APIs and mentions some alternatives if you want to use something else.

Expand Down
4 changes: 2 additions & 2 deletions docs/guide/essentials/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

[Chrome Docs](https://developer.chrome.com/docs/extensions/develop/concepts/messaging)[Firefox Docs](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#communicating_with_background_scripts)

The vanilla APIs for sending messages are difficult to use, but possible. Read the docs linked above to learn more.
Read the docs linked above to learn more about using the vanilla messaging APIs.

## Alternatives

Instead of using the APIs directly, it's recommended to install an NPM package that wraps around the vanilla APIs.
The vanilla APIs are difficult to use and are a pain point to many new extension developers. For this reason, WXT recommends installing an NPM package that wraps around the vanilla APIs.

Here are some popular messaging libraries that support all browsers and work with WXT:

Expand Down
2 changes: 1 addition & 1 deletion docs/guide/essentials/project-structure.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default defineConfig({
outDir: "dist", // default: ".output"

// Relative to srcDir
entrypointsDir: "entries", // default: "entrtypoints"
entrypointsDir: "entries", // default: "entrypoints"
modulesDir: "wxt-modules", // default: "modules"
publicDir: "static", // default: "public"
})
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/essentials/publishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ wxt zip -b firefox

Then run the `wxt submit` command, passing in all the ZIP files you want to release. In this case, we'll do a release for all 3 major stores: Chrome Web Store, Edge Addons, and Firefox Addons Store.

If it's your first time running the command or you recently made changes to the release process, you'll want to test your secrets by passing the `--dry-run` flag:
If it's your first time running the command or you recently made changes to the release process, you'll want to test your secrets by passing the `--dry-run` flag.

```sh
wxt submit --dry-run \
Expand Down Expand Up @@ -175,7 +175,7 @@ Ensure that you have a `README.md` or `SOURCE_CODE_REVIEW.md` file with the abov
Make sure the build output is the exact same when running `wxt build -b firefox` in your main project and inside the zipped sources.

:::warning
If you use a `.env` files, they can effect the chunk hashes in the output directory. Either delete the .env file before running `wxt zip -b firefox`, or include it in your sources zip with the [`zip.includeSources`](/api/reference/wxt/interfaces/InlineConfig#includesources) option. Be careful to not include any secrets in your `.env` files.
If you use a `.env` files, they can affect the chunk hashes in the output directory. Either delete the .env file before running `wxt zip -b firefox`, or include it in your sources zip with the [`zip.includeSources`](/api/reference/wxt/interfaces/InlineConfig#includesources) option. Be careful to not include any secrets in your `.env` files.

See Issue [#377](https://github.com/wxt-dev/wxt/issues/377) for more details.
:::
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/essentials/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ You can use the vanilla APIs (see docs above), use [WXT's built-in storage API](

## Alternatives

1. [`wxt/storage`](/storage) (recommended): WXT ships with it's own wrapper around the vanilla storage APIs, and it is the recommended way to persist data in WXT projects.
1. [`wxt/storage`](/storage) (recommended): WXT ships with its own wrapper around the vanilla storage APIs that simplifies common use cases

2. DIY: If you're migrating to WXT and already have a storage wrapper, keep using it. In the future, if you want to delete that code, you can use one of these alternatives, but there's no reason to replace working code during a migration.

3. Any other NPM package: [There are lots of wrappers around the storage API](https://www.npmjs.com/search?q=chrome%20storage), you can find one you like. Here's some popular ones:
- [`webext-storage`](https://www.npmjs.com/package/webext-storage) - A more usable typed storage API for Web Extensions
- [`@webext-core/storage`](https://www.npmjs.com/package/@webext-core/storage) - A type-safe, localStorage-esk wrapper around the web extension storage APIs
- [`@webext-core/storage`](https://www.npmjs.com/package/@webext-core/storage) - A type-safe, localStorage-esque wrapper around the web extension storage APIs
10 changes: 5 additions & 5 deletions docs/guide/essentials/target-different-browsers.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Targetting Different Browsers
# Targeting Different Browsers

When building an extension with WXT, you can create multiple builds of your extension targetting different browsers and manifest versions.
When building an extension with WXT, you can create multiple builds of your extension targeting different browsers and manifest versions.

## Target a Browser

Expand All @@ -12,18 +12,18 @@ wxt -b firefox
wxt -b custom
```

Targetting a browser has several effects:
Targeting a browser has several effects:

1. During development, when passing `firefox`, WXT will automatically open Firefox with the extension installed. For all other browsers, it will open Chrome/Chromium
2. Changes build-time constants provided by WXT:
- `import.meta.env.BROWSER`: A string, the targetted browser
- `import.meta.env.BROWSER`: A string, the targeted browser
- `import.meta.env.CHROME`: A boolean equivalent to `import.meta.env.BROWSER === "chrome"`
- `import.meta.env.FIREFOX`: A boolean equivalent to `import.meta.env.BROWSER === "firefox"`
- `import.meta.env.EDGE`: A boolean equivalent to `import.meta.env.BROWSER === "edge"`
- `import.meta.env.SAFARI`: A boolean equivalent to `import.meta.env.BROWSER === "safari"`
- `import.meta.env.OPERA`: A boolean equivalent to `import.meta.env.BROWSER === "opera"`

## Target a Manfifest Version
## Target a Manifest Version

To target specific manifest versions, use the `--mv2` or `--mv3` CLI flags.

Expand Down
Loading

0 comments on commit dee9511

Please sign in to comment.