Skip to content

Background service worker : document is not defined  #392

@lionelhorn

Description

@lionelhorn

Describe the bug

In background context : If imported code from third party librariries are using document, the background script may fail to start or load with Uncaught ReferenceError: document is not defined error.

To Reproduce

https://github.com/lionelhorn/wxt-wasm-vlcn-repro

Steps to reproduce the bug using the reproduction:

  1. Install dependencies: pnpm i
  2. Start dev mode: pnpm dev
  3. Open chrome://extensions/
  4. Reload wxt-wasm-vlcn-repro extension
  5. Open errors

Expected behavior

Background script / service worker to start without errors.

Screenshots

image

Environment

  System:
    OS: Windows 11 10.0.22631
    CPU: (32) x64 AMD Ryzen 9 7950X 16-Core Processor
    Memory: 33.11 GB / 63.15 GB
  Binaries:
    Node: 18.18.2 - C:\Program Files\nodejs\node.EXE
    npm: 10.2.1 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.14.0 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (121.0.2277.83)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions