Skip to content

Comments

Improve WebKit notify rejection handling#2244

Draft
laghee wants to merge 2 commits intomainfrom
km/fix-unhandled-promise-missing-native
Draft

Improve WebKit notify rejection handling#2244
laghee wants to merge 2 commits intomainfrom
km/fix-unhandled-promise-missing-native

Conversation

@laghee
Copy link
Contributor

@laghee laghee commented Feb 7, 2026

Asana Task/Github Issue: https://app.asana.com/1/137249556945/task/1213169335457201

Description

The performanceMetrics feature is missing an handler on the Apple side, and the way we currently handle this seems to be causing bot breakage possibly due to one or more of the following:

  • WebKit behavior quirk: In some WebKit versions, unhandledrejection events from isolated content worlds can leak to the page's window, making them visible to page scripts.
  • Error fingerprinting: Bot detection systems may monitor for unusual error patterns. DuckDuckGo-specific error messages like "feature named performanceMetrics was not found" could be flagged as anomalous browser behavior.
  • Message handler saturation: If the error causes the native message handler to behave unexpectedly, it could delay or block other legitimate messages through the same contentScopeScriptsIsolated channel, potentially affecting features that the bot check depends on.

Proposed fix:
The notify() method in WebkitMessagingTransport (webkit.js) should catch the promise rejection from postMessage() to prevent unhandled rejections even when a native handler is missing. Something like catching the return value of wkSend with .catch(() => {}) for the modern WebKit API path would align with the fire-and-forget semantics of notifications.

Testing Steps

Checklist

Please tick all that apply:

  • I have tested this change locally
  • I have tested this change locally in all supported browsers
  • This change will be visible to users
  • I have added automated tests that cover this change
  • I have ensured the change is gated by config
  • This change was covered by a ship review
  • This change was covered by a tech design
  • Any dependent config has been merged

Note

Medium Risk
Behavior change in the WebKit messaging transport could mask real native-side failures for notifications, and the added async handling affects all notification sends on modern WebKit.

Overview
Prevents WebKit notification sends from leaking unhandled promise rejections by having WebkitMessagingTransport.notify() detect a promise return from wkSend() and attach a no-op .catch().

Adds automated coverage: new unit tests validate notify() doesn’t create process-level unhandledRejections for rejecting/resolving/sync postMessage returns, and new Playwright integration tests plus fixture pages/configs exercise performanceMetrics message emission (FCP, expanded metrics, vitals subscription) including disabled-settings and iframe cases.

Written by Cursor Bugbot for commit b94278a. This will update automatically on new commits. Configure here.


…ed rejections

On modern WebKit (macOS 11+, iOS 14+), postMessage() returns a Promise via
WKScriptMessageHandlerWithReply. When a native handler is missing for a
feature, the promise rejects. The notify() method (fire-and-forget) was not
catching this rejection, causing unhandled promise rejections that interfere
with bot-check scripts like Cloudflare Turnstile.

This adds a .catch() guard on the promise returned by wkSend() in the
WebkitMessagingTransport.notify() method, aligning with the fire-and-forget
semantics of notifications.

Includes unit tests verifying no unhandled rejections occur when postMessage
rejects, resolves, or returns undefined.
Tests cover:
- FCP notification is sent when firstContentfulPaint is enabled
- Expanded metrics notification is sent after page load
- vitalsResult is sent in response to getVitals subscription
- No FCP/expanded messages when sub-settings are disabled
- Expanded metrics are not sent when only FCP is enabled
- Expanded metrics include firstContentfulPaint value
- FCP/expanded metrics are not sent in iframes (isBeingFramed guard)
@netlify
Copy link

netlify bot commented Feb 7, 2026

Deploy Preview for content-scope-scripts ready!

Name Link
🔨 Latest commit b94278a
🔍 Latest deploy log https://app.netlify.com/projects/content-scope-scripts/deploys/69875bb05c258a0008d8358d
😎 Deploy Preview https://deploy-preview-2244--content-scope-scripts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

Temporary Branch Update

The temporary branch has been updated with the latest changes. Below are the details:

Please use the above install command to update to the latest version.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

[Beta] Generated file diff

Time updated: Sat, 07 Feb 2026 15:36:16 GMT

Android
    - android/adsjsContentScope.js
  • android/autofillImport.js
  • android/brokerProtection.js
  • android/contentScope.js
  • android/pages/duckplayer/dist/index.js

File has changed

Chrome-mv3
    - chrome-mv3/inject.js

File has changed

Firefox
    - firefox/inject.js

File has changed

Integration
    - integration/contentScope.js
  • integration/pages/duckplayer/dist/index.js
  • integration/pages/example/dist/index.js
  • integration/pages/history/dist/index.js
  • integration/pages/new-tab/dist/index.js
  • integration/pages/onboarding/dist/index.js
  • integration/pages/release-notes/dist/index.js
  • integration/pages/special-error/dist/index.js

File has changed

Windows
    - windows/contentScope.js
  • windows/pages/duckplayer/dist/index.js
  • windows/pages/history/dist/index.js
  • windows/pages/new-tab/dist/index.js
  • windows/pages/onboarding/dist/index.js
  • windows/pages/release-notes/dist/index.js
  • windows/pages/special-error/dist/index.js
  • windows/pages/special-error/index.html

File has changed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants