Skip to content
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

Premature context invalidation for content scripts #1359

Open
5 tasks done
DenizUgur opened this issue Jan 21, 2025 · 0 comments · May be fixed by #1364
Open
5 tasks done

Premature context invalidation for content scripts #1359

DenizUgur opened this issue Jan 21, 2025 · 0 comments · May be fixed by #1364
Labels
pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug

Comments

@DenizUgur
Copy link

Describe the bug

I've noticed that ContentScriptContext would get invalidated prematurely and therefore restrict any further use of wxt APIs. Initially I thought I missed some configuration with wxt but the minimal reproduction I've described below indicates that there might be a bug with wxt itself.

Reproduction

Either use the attached archive or follow the steps below:

  1. Initialize a vanilla extension via pnpm dlx wxt@latest init
  2. Use the following script as your content script.
  3. This issue does not occur on all pages but try the documentation from Google: https://developers.google.com/docs/api/reference/rest
  4. Sometimes this script will work be sometimes not. But the event listener without ctx will always work.
export default defineContentScript({
  matches: ["<all_urls>"],
  main(ctx) {
    console.log("Content script loaded", ctx.isValid);
    setInterval(
      () => console.log("Content script is alive", ctx.isValid),
      1000
    );
    window.addEventListener("keydown", (e) =>
      console.log("works without ctx", e.key)
    );
    ctx.addEventListener(window, "keydown", (e) =>
      console.log("doesn't work with ctx", e.key)
    );
  },
});

Reproduction archive: test.zip

Steps to reproduce

No response

System Info

System:
    OS: Linux 6.11 Ubuntu 24.10 24.10 (Oracular Oriole)
    CPU: (32) x64 Intel(R) Core(TM) i9-14900K
    Memory: 49.19 GB / 61.56 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.13.0 - ~/.nvm/versions/node/v22.13.0/bin/node
    npm: 10.9.2 - ~/.nvm/versions/node/v22.13.0/bin/npm
    pnpm: 9.15.3 - ~/.local/share/pnpm/pnpm
  Browsers:
    Chrome: 132.0.6834.83

Used Package Manager

pnpm

Validations

@DenizUgur DenizUgur added the pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug label Jan 21, 2025
DenizUgur added a commit to DenizUgur/wxt that referenced this issue Jan 22, 2025
> This fix prevents premature context invalidation
> fixes wxt-dev#1359
@DenizUgur DenizUgur linked a pull request Jan 22, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant