-
- Notifications
You must be signed in to change notification settings - Fork 405
Labels
pending-triageSomeone (usually a maintainer) needs to look into this to see if it's a bugSomeone (usually a maintainer) needs to look into this to see if it's a bug
Description
Describe the bug
For example, the following inject.ts script will be executed using browser.devtools.inspectedWindow.eval
.
export default defineUnlistedScript(() => { // @ts-expect-error if (!globalThis.$0) { return } // @ts-expect-error return globalThis.$0.childElementCount })
The expected return value is number/undefined, but it always returns {}
. After careful inspection, I found this script is compiled into
var inject = (function() { "use strict"; function defineUnlistedScript(arg) { if (arg == null || typeof arg === "function") return { main: arg }; return arg; } const definition = defineUnlistedScript(() => { if (!globalThis.$0) { return; } return globalThis.$0.childElementCount; }); function initPlugins() { } const result = (async () => { try { initPlugins(); return await definition.main(); } catch (err) { logger.error( `The unlisted script "${"inject"}" crashed on startup!`, err ); throw err; } })(); return result; })();
The key issue is that await definition.main()
assumes all defined functions return Promises, when in fact they don't. The expected behavior should properly handle both Promise and non-Promise scenarios.

Reproduction
https://github.com/rxliuli/wxt-error-define-unlisted-script-promise
Steps to reproduce
git clone https://github.com/rxliuli/wxt-error-define-unlisted-script-promise
pnpm i && pnpm dev
Open any webpage
Open Devtools > Element
Select Element
System Info
System: OS: macOS 26.0 CPU: (12) arm64 Apple M2 Max Memory: 21.25 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.14.0 - /usr/local/bin/node npm: 10.9.2 - /usr/local/bin/npm pnpm: 10.10.0 - /usr/local/bin/pnpm bun: 1.1.6 - ~/.bun/bin/bun Browsers: Brave Browser: 131.1.73.105 Chrome: 140.0.7339.186 Edge: 128.0.2739.54 Safari: 26.0 npmPackages: wxt: ^0.20.6 => 0.20.11
Used Package Manager
pnpm
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
pending-triageSomeone (usually a maintainer) needs to look into this to see if it's a bugSomeone (usually a maintainer) needs to look into this to see if it's a bug