Skip to content

feat: Add content script noScriptStartedPostMessage option#2265

Merged
aklinker1 merged 3 commits into
wxt-dev:mainfrom
jviney:add-content-script-noScriptStartedPostMessage-option
May 11, 2026
Merged

feat: Add content script noScriptStartedPostMessage option#2265
aklinker1 merged 3 commits into
wxt-dev:mainfrom
jviney:add-content-script-noScriptStartedPostMessage-option

Conversation

@jviney
Copy link
Copy Markdown
Contributor

@jviney jviney commented Apr 14, 2026

Overview

The deprecated window.postMessage path for the wxt:content-script-started message causes bad interactions with sites that have a poorly implemented event listener. Eg a previously dormant event listener like this is now triggered to become an infinite loop of message passing:

window.addEventListener("message", (event) => {
  event.source.postMessage("something")
})

This PR adds an option to exclude the window.postMessage event entirely, until such time as WXT completely removes it, which is a breaking change.

There are two recent PRs that discuss the move away from window.postMessage to custom events.
#1938
#2035

Manual Testing

Checked the postMessage is no longer sent to the window.

Simple reproduction of the issue:

<!DOCTYPE html>
<html lang="en">
<head>
    <script>
      window.addEventListener("message", (e) => {
        console.log("GOT MESSAGE", e, e.detail)
        e.source.postMessage("Hello from the message handler!", "*")
      })
    </script>
    <title>Hello World</title>
</head>
<body>
    <h1>Hello, World!</h1>
</body>
</html>

@jviney jviney requested a review from aklinker1 as a code owner April 14, 2026 00:40
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 14, 2026

Deploy Preview for creative-fairy-df92c4 ready!

Name Link
🔨 Latest commit 2de4b23
🔍 Latest deploy log https://app.netlify.com/projects/creative-fairy-df92c4/deploys/6a01c9c05e41e2000865e4ca
😎 Deploy Preview https://deploy-preview-2265--creative-fairy-df92c4.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@github-actions github-actions Bot added the pkg/wxt Includes changes to the `packages/wxt` directory label Apr 14, 2026
The deprecated `window.postMessage` path for the `wxt:content-script-started` message causes bad interactions with sites that have a poorly implemented event listener.

This PR adds an option to exclude the `window.postMessage` event entirely, until such time as WXT completely removes it, which is a breaking change.

Related PRs
wxt-dev#1938
wxt-dev#2035
@jviney jviney force-pushed the add-content-script-noScriptStartedPostMessage-option branch from 4319253 to 280df61 Compare April 14, 2026 00:40
@wooly
Copy link
Copy Markdown

wooly commented May 11, 2026

Tiny bump on this one if you've got some free time, @aklinker1

@aklinker1
Copy link
Copy Markdown
Member

Thanks for the ping! We'll get this merged and released today.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 11, 2026

Open in StackBlitz

@wxt-dev/analytics

npm i https://pkg.pr.new/@wxt-dev/analytics@2265

@wxt-dev/auto-icons

npm i https://pkg.pr.new/@wxt-dev/auto-icons@2265

@wxt-dev/browser

npm i https://pkg.pr.new/@wxt-dev/browser@2265

@wxt-dev/i18n

npm i https://pkg.pr.new/@wxt-dev/i18n@2265

@wxt-dev/is-background

npm i https://pkg.pr.new/@wxt-dev/is-background@2265

@wxt-dev/module-react

npm i https://pkg.pr.new/@wxt-dev/module-react@2265

@wxt-dev/module-solid

npm i https://pkg.pr.new/@wxt-dev/module-solid@2265

@wxt-dev/module-svelte

npm i https://pkg.pr.new/@wxt-dev/module-svelte@2265

@wxt-dev/module-vue

npm i https://pkg.pr.new/@wxt-dev/module-vue@2265

@wxt-dev/runner

npm i https://pkg.pr.new/@wxt-dev/runner@2265

@wxt-dev/storage

npm i https://pkg.pr.new/@wxt-dev/storage@2265

@wxt-dev/unocss

npm i https://pkg.pr.new/@wxt-dev/unocss@2265

@wxt-dev/webextension-polyfill

npm i https://pkg.pr.new/@wxt-dev/webextension-polyfill@2265

wxt

npm i https://pkg.pr.new/wxt@2265

commit: 2de4b23

Comment thread packages/wxt/src/types.ts Outdated
@aklinker1 aklinker1 changed the title Add content script noScriptStartedPostMessage option. feat: Add content script noScriptStartedPostMessage option May 11, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.41%. Comparing base (a0a2394) to head (2de4b23).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2265      +/-   ##
==========================================
- Coverage   78.53%   78.41%   -0.13%     
==========================================
  Files         133      133              
  Lines        3876     3877       +1     
  Branches      870      871       +1     
==========================================
- Hits         3044     3040       -4     
- Misses        746      749       +3     
- Partials       86       88       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@aklinker1 aklinker1 enabled auto-merge (squash) May 11, 2026 12:17
@aklinker1 aklinker1 merged commit f771e6a into wxt-dev:main May 11, 2026
18 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for helping make WXT better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg/wxt Includes changes to the `packages/wxt` directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants