Skip to content

fix(webext): provide idle callbacks in extension windows - #348

Open
mydd7 wants to merge 1 commit into
zephium-browser:mainfrom
mydd7:fix/webext-idle-callback
Open

mydd7 wants to merge 1 commit into
zephium-browser:mainfrom
mydd7:fix/webext-idle-callback

Conversation

@mydd7

@mydd7 mydd7 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Reddit Enhancement Suite's content script stops at requestIdleCallback when WebKit does not provide that global (#344). The extension compatibility layer now provides request/cancel idle callbacks in extension pages and content-script contexts when the request API is missing.

The fallback yields through a timer and supplies a decreasing budget capped at 50 ms. If the requested positive timeout has elapsed before delivery, it reports didTimeout: true with no remaining budget. Cancellation removes the timer. Native implementations are retained; workers and ordinary page-world scripts do not gain this Window API.

This is a timer-based compatibility fallback, not WebKit idle detection. Deadline and timeout behavior follow the requestIdleCallback specification. The separate diagnostics suggestion in #344 is outside this change.

Validation on Windows:

  • Before the fix: 4 new cases failed because requestIdleCallback was absent; 18 passed.
  • node --test crates/zephium-webext-macos/tests/compat.test.mjs: all 22 passed.
  • Tests cover deferred execution, cancellation, decreasing/nonnegative budgets, elapsed and unexpired timeouts, native preservation, worker scope and page-world isolation.
  • cargo test -p zephium-webext-macos --locked: the Node integration harness passed. This is not a macOS native build.
  • cargo clippy -p zephium-webext-macos --all-targets --locked -- -D warnings
  • cargo fmt --all --check, JavaScript syntax checks and git diff --check passed.

RES startup in a packaged macOS build still needs verification. No Rust, IPC or frame code changed.

Summary by CodeRabbit

  • New Features
    • Added support for scheduling and cancelling idle callbacks in supported page and content contexts where native idle-callback APIs are unavailable.
    • Callbacks run asynchronously and receive a time budget; optional timeouts determine whether a callback is reported as timed out.
    • Existing native behavior is preserved, and these APIs remain unavailable in worker contexts and ordinary pages without extension context.

@mydd7
mydd7 requested a review from crynta as a code owner November 2, 2026 06:20
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between f0dba76 and e89c662.

Files selected for processing: 2
  • crates/zephium-webext-macos/src/compat/compat.js
  • crates/zephium-webext-macos/tests/compat.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The macOS compatibility layer adds timer-backed requestIdleCallback and cancelIdleCallback APIs in supported extension contexts. Tests cover asynchronous callbacks, deadlines, timeouts, cancellation, native API retention, and context-specific availability.

Changes: Idle callback fallback

Layer / File(s) Summary
Fallback behavior and context validation
crates/zephium-webext-macos/src/compat/compat.js, crates/zephium-webext-macos/tests/compat.test.mjs
The compatibility layer adds a timer-backed idle callback implementation with callback validation, timeout handling, a deadline, and cancellation. Tests cover page and content contexts, native API retention, and contexts where the APIs remain unavailable.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

  • Issue 344 reports a missing requestIdleCallback in WebKit RES content scripts. This change adds a fallback for content-script contexts.

Suggested labels: bug, area: extensions, platform: macos, size: S

Merge Risk: Low · up to e89c6

Passing an unrelated timer handle to idle cancellation can stop that timer. Normal use is unaffected, so the risk is bounded.

Pre-merge checks: Passed 9 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Performance Impact Stated Warning The change touches startup code. compat.js runs first in every extension context, and the new block adds initialization in non-worker pages and content scripts. The description explains timer and de… Add a Performance Impact section to the PR description. State the added startup work, the per-call timer overhead when the fallback is used, and whether the change affects content-script or extension-page startup. Include measured startup o…
Passed Passed checks: 9 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title uses the required Conventional Commits format with the valid type fix, scope webext, and an imperative summary that accurately describes the idle callback fallback change.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
One Logical Change Passed The pull request changes only compat.js and its compatibility test file. The implementation adds the described idle-callback fallback, and the test changes support and verify that behavior. The diff…
Linked Issue For Larger Changes Passed The PR is a small, contained bug fix. The diff changes only the compatibility layer and its tests, and adds fallback idle callbacks for the reported WebKit gap. It does not add a broad feature, alter …
Tests Cover Changed Behavior Passed The PR adds tests for the changed idle-callback behavior. The tests cover asynchronous delivery, the 50 ms decreasing and nonnegative deadline, expired and unexpired timeouts, cancellation, invalid ca…
Generated Files Follow Their Source Passed The pull request changes only crates/zephium-webext-macos/src/compat/compat.js and its test file. It does not change frame/src/shared/ipc/bindings.ts, Cargo.lock, pnpm-lock.yaml, or generated …
Privileged Boundary Intact Passed The authoritative diff contains only compat.js and compat.test.mjs. The production change adds local timer-based requestIdleCallback and cancelIdleCallback functions. It does not add Tauri IPC…
Full details: One Logical Change

Explanation

The pull request changes only compat.js and its compatibility test file. The implementation adds the described idle-callback fallback, and the test changes support and verify that behavior. The diff contains no unrelated refactoring, renaming, or reformatting.

Full details: Linked Issue For Larger Changes

Explanation

The PR is a small, contained bug fix. The diff changes only the compatibility layer and its tests, and adds fallback idle callbacks for the reported WebKit gap. It does not add a broad feature, alter user-facing UI, or refactor across modules. The check therefore passes even though the description uses a plain issue reference rather than a Closes/Fixes/Refs keyword.

Full details: Tests Cover Changed Behavior

Explanation

The PR adds tests for the changed idle-callback behavior. The tests cover asynchronous delivery, the 50 ms decreasing and nonnegative deadline, expired and unexpired timeouts, cancellation, invalid callbacks (TypeError), native API preservation, worker exclusion, and ordinary page-world exclusion. The changed file is JavaScript, not Rust or TypeScript.

Full details: Generated Files Follow Their Source

Explanation

The pull request changes only crates/zephium-webext-macos/src/compat/compat.js and its test file. It does not change frame/src/shared/ipc/bindings.ts, Cargo.lock, pnpm-lock.yaml, or generated i18n output. No source/generated-file mismatch condition applies.

Full details: Privileged Boundary Intact

Explanation

The authoritative diff contains only compat.js and compat.test.mjs. The production change adds local timer-based requestIdleCallback and cancelIdleCallback functions. It does not add Tauri IPC, a Wry IPC handler, privileged initialization, a custom protocol, CSP or devtools settings, or Rust commands. Therefore none of the stated boundary failures is introduced.

Full details: Performance Impact Stated

Explanation

The change touches startup code. compat.js runs first in every extension context, and the new block adds initialization in non-worker pages and content scripts. The description explains timer and deadline behavior, but it does not state the performance impact of startup initialization or fallback calls, and it gives no performance measurement.

Resolution

Add a Performance Impact section to the PR description. State the added startup work, the per-call timer overhead when the fallback is used, and whether the change affects content-script or extension-page startup. Include measured startup or callback overhead if available.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot added area: extensions Web extensions bug Something isn't working platform: macos macOS-specific size: S Under 100 changed lines labels Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: extensions Web extensions bug Something isn't working platform: macos macOS-specific size: S Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant