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

Allow scripts to not register with manifest.json for MV2 #1428

Open
5 tasks done
harmonyharmo opened this issue Feb 13, 2025 · 2 comments · May be fixed by #1431
Open
5 tasks done

Allow scripts to not register with manifest.json for MV2 #1428

harmonyharmo opened this issue Feb 13, 2025 · 2 comments · May be fixed by #1431

Comments

@harmonyharmo
Copy link

Describe the bug

  • should allow scripts to not register with manifest.json for MV2
  • It's ok it doesn't use the MV3 specific runtime features

Reproduction

should allow scripts to not register with manifest.json for MV2
It's ok it doesn't use the MV3 specific runtime features

runtimeContentScripts.length > 0 &&

Steps to reproduce

  • set registration to runtime in MV2
  • Gets error when building

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (24) x64 13th Gen Intel(R) Core(TM) i7-13700
    Memory: 13.12 GB / 31.77 GB
  Binaries:
    Node: 23.7.0 - ~\scoop\apps\nodejs\current\node.EXE        
    Yarn: 1.22.22 - ~\scoop\apps\yarn\current\bin\yarn.CMD     
    npm: 11.0.0 - ~\scoop\apps\nodejs\current\npm.CMD
    pnpm: 10.3.0 - ~\scoop\shims\pnpm.EXE
    bun: 1.2.2 - ~\scoop\shims\bun.EXE
  Browsers:
    Edge: Chromium (131.0.2903.70)
    Internet Explorer: 11.0.26100.1882

Used Package Manager

bun

Validations

@harmonyharmo harmonyharmo added the pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug label Feb 13, 2025
@aklinker1
Copy link
Collaborator

Hmm, well unfortunately I don't remember why I did that lol. Feel free to open a PR to remove that check!

@aklinker1 aklinker1 added contribution welcome and removed pending-triage Someone (usually a maintainer) needs to look into this to see if it's a bug labels Feb 13, 2025
@aklinker1
Copy link
Collaborator

In the meantime, you can just use an unlisted script. If you need context, you can just create it:

// entrypoints/my-content-script.content.ts
export default defineUnlistedScript(() => {
  const ctx = new ContentScriptContext("my-content-script");
});

Just make sure the first argument, the entrypoint name, is unique to this script, and no other entrypoints have the same name.

There's nothing magic about the ctx object WXT provides to content scripts, it's just a class, and WXT just constructs it before calling the content script's main function:

const { main, ...options } = definition;
const ctx = new ContentScriptContext(import.meta.env.ENTRYPOINT, options);
return await main(ctx);

harmonyharmo added a commit to harmonyharmo/wxt that referenced this issue Feb 13, 2025
@harmonyharmo harmonyharmo linked a pull request Feb 13, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants