wxt-dev / wxt-dev/wxt

Built-in support for Content Scripts running in SPAs

Open
#1,029 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

contribution welcome
Dominant language
TypeScript
Stars
10.5k
Forks
564
PR merge metrics
No merged PRs in 30d

Description

Feature Request

Dealing with loading your content script correctly in SPAs is really annoying. WXT should be able to do it for you.

export default defineContentScript({
  matches: ['*://*.youtube.com/watch*'],
  spa: true,

  main(ctx) {
    console.log('YouTube content script loaded');
    mountUi(ctx);
  },
});
Is your feature request related to a bug?

N/A

What are the alternatives?

As the docs state, manually listening to URL changes works. But managing ctx correctly is annoying, and not shown in the docs. This would also create ctx for each URL path, so the script can shut down properly when the path changes.

Additional context
Screenshot 2024-10-03 at 1 01 49 PM

https://discord.com/channels/1212416027611365476/1224500470278520904/1291359490121138207

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the defineContentScript API and the existing documentation for manually handling URL changes in SPAs. Determine how content-script contexts are created and stopped across path changes, then verify that the proposed spa option loads the script on matching routes and cleans up the prior context.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.