Repository navigation
Fix background Chrome fill timeouts #13
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import assert from "node:assert/strict"; | ||
| import fs from "node:fs/promises"; | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import vm from "node:vm"; | ||
|
|
||
| const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), ".."); | ||
| const workerSource = await fs.readFile(path.join(root, "chrome-extension", "service-worker.js"), "utf8"); | ||
| const match = workerSource.match(/async function pageFill\([\s\S]*?\n}\n\nasync function executeInTab/); | ||
| assert.ok(match, "pageFill source should be extractable for the background-frame regression"); | ||
| const pageFillSource = match[0].replace(/\n\nasync function executeInTab$/, ""); | ||
|
|
||
| class FakeInputElement { | ||
| constructor() { | ||
| this._value = ""; | ||
| this.type = "text"; | ||
| this.events = []; | ||
| this.isContentEditable = false; | ||
| } | ||
| get value() { return this._value; } | ||
| set value(next) { this._value = String(next); } | ||
| focus() {} | ||
| select() {} | ||
| dispatchEvent(event) { this.events.push(event.type); return true; } | ||
| closest() { return null; } | ||
| } | ||
| class FakeTextAreaElement extends FakeInputElement {} | ||
| class FakeSelectElement extends FakeInputElement { | ||
| constructor() { | ||
| super(); | ||
| this.options = []; | ||
| } | ||
| } | ||
| class FakeEvent { | ||
| constructor(type, init = {}) { | ||
| this.type = type; | ||
| Object.assign(this, init); | ||
| } | ||
| } | ||
|
|
||
| const element = new FakeTextAreaElement(); | ||
| const context = vm.createContext({ | ||
| document: { | ||
| title: "Background Reddit composer", | ||
| querySelector: () => element, | ||
| execCommand: () => false, | ||
| }, | ||
| location: { href: "https://old.reddit.com/r/test/comments/example/" }, | ||
| HTMLInputElement: FakeInputElement, | ||
| HTMLTextAreaElement: FakeTextAreaElement, | ||
| HTMLSelectElement: FakeSelectElement, | ||
| InputEvent: FakeEvent, | ||
| Event: FakeEvent, | ||
| KeyboardEvent: FakeEvent, | ||
| // Deliberately never invoke the callback: Chrome can suspend rAF in an | ||
| // inactive background tab, which previously left chrome_fill unresolved. | ||
| requestAnimationFrame: () => 1, | ||
| setTimeout, | ||
| clearTimeout, | ||
| }); | ||
| const pageFill = vm.runInContext(`(${pageFillSource})`, context); | ||
|
|
||
| const startedAt = Date.now(); | ||
| const result = await Promise.race([ | ||
| pageFill('textarea[name="text"]', "background fill succeeds", false), | ||
| new Promise((_, reject) => setTimeout(() => reject(new Error("pageFill hung on suspended requestAnimationFrame")), 1_500)), | ||
| ]); | ||
| const elapsedMs = Date.now() - startedAt; | ||
|
|
||
| assert.equal(result.filled, true); | ||
| assert.equal(result.submitted, false); | ||
| assert.equal(element.value, "background fill succeeds"); | ||
| assert.deepEqual(element.events, ["input", "change"]); | ||
| assert.ok(elapsedMs >= 200, `expected the bounded fallback to be exercised, got ${elapsedMs}ms`); | ||
| assert.ok(elapsedMs < 1_250, `background fill should settle well before the transport timeout, got ${elapsedMs}ms`); | ||
|
|
||
| console.log(JSON.stringify({ passed: true, elapsedMs, value: element.value })); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bumping only the manifest leaves
VERSIONinservice-worker.jsat0.2.7. After installing this0.2.8extension, the native-host ready message and thestatusandextension.reloadresponses therefore still identify it as0.2.7, preventing callers and diagnostics from confirming that the updated worker is actually running. Update the runtime constant as part of this version bump, or derive it fromchrome.runtime.getManifest().version.Useful? React with 👍 / 👎.