fix: a slow answer to an approval still reaches the site (closes #540)
Chrome stopped the background worker about six minutes after a site's request even with the approval window open, and the approval and the site's waiting request went with it. While any approval is pending, the worker now calls runtime.getPlatformInfo() every 20 seconds; Chrome counts each extension call as activity. The timer is the worker's own, so a minimized window does not slow it, and it stops itself once nothing is pending. tests/e2e/slowApproval.js, run by make test-e2e, leaves a transaction and a signature approval open for seven minutes in minimized windows and requires the site to receive both results. It drives Chromium over the DevTools pipe without Playwright, because Playwright keeps DevTools attached to the worker and Chrome then never stops it. Model: opus-5-5
This commit is contained in:
@@ -264,6 +264,7 @@ function loadBackground(options) {
|
||||
connectListener = fn;
|
||||
},
|
||||
},
|
||||
getPlatformInfo: jest.fn((cb) => cb({ os: "linux" })),
|
||||
lastError: null,
|
||||
},
|
||||
windows: {
|
||||
@@ -878,6 +879,43 @@ describe("one transaction approval at a time", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// Chrome stops an idle worker, and the approvals in it go with it
|
||||
// (https://git.eeqj.de/sneak/AutistMask/issues/540). tests/e2e/slowApproval.js
|
||||
// shows the worker kept running in Chrome; this shows the calls stop once the
|
||||
// approval is answered, so the worker can stop again.
|
||||
describe("the worker keeps running while an approval is pending", () => {
|
||||
test("an extension call every 20 seconds until the approval is answered", async () => {
|
||||
const startTimer = jest
|
||||
.spyOn(global, "setInterval")
|
||||
.mockImplementation(() => 1);
|
||||
const stopTimer = jest
|
||||
.spyOn(global, "clearInterval")
|
||||
.mockImplementation(() => {});
|
||||
try {
|
||||
const bg = loadBackground();
|
||||
const calls = global.chrome.runtime.getPlatformInfo;
|
||||
bg.requestTx();
|
||||
await settle();
|
||||
expect(startTimer).toHaveBeenCalledTimes(1);
|
||||
expect(startTimer.mock.calls[0][1]).toBe(20000);
|
||||
const tick = startTimer.mock.calls[0][0];
|
||||
|
||||
tick();
|
||||
expect(calls).toHaveBeenCalledTimes(1);
|
||||
|
||||
// The user closes the approval window, which rejects it.
|
||||
bg.closeWindow(1);
|
||||
await settle();
|
||||
tick();
|
||||
expect(calls).toHaveBeenCalledTimes(1);
|
||||
expect(stopTimer).toHaveBeenCalledWith(1);
|
||||
} finally {
|
||||
startTimer.mockRestore();
|
||||
stopTimer.mockRestore();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// A page that asks again before the user has answered its last connection or
|
||||
// signature request is refused, instead of opening one more window per call.
|
||||
describe("one connection and one signature approval per site at a time", () => {
|
||||
|
||||
Reference in New Issue
Block a user