fix: a popup reload mid-refresh no longer logs the requests it cancels (closes #218)
Chrome cancels a closing popup's open requests just after pagehide, and in the page a cancelled fetch() fails with the same "Failed to fetch" as a server that cannot be reached. The home screen's transaction list and the balance refresh logged an error for each, and the e2e suite failed on them. The popup now aborts an AbortController on pagehide, and those failure reports check its signal first. End-to-end tests reload the popup with Blockscout held and require nothing logged, and fail the transaction list for real and require the failure reported; a unit test covers the balance refresh. The address and token screens and the new-wallet address scan are #475. Model: opus-5-5
This commit was merged in pull request #476.
This commit is contained in:
@@ -48,6 +48,14 @@ function renderWalletList() {
|
||||
home.render(ctx);
|
||||
}
|
||||
|
||||
// Aborted when the popup page goes away, closed or reloaded. Chrome then
|
||||
// cancels the requests the page still has open, and a cancelled fetch() fails
|
||||
// with the same "Failed to fetch" as a server that cannot be reached. pagehide
|
||||
// fires first, so code that reports a failed request checks this and stays
|
||||
// silent about one the page's own closing cancelled.
|
||||
const pageClosed = new AbortController();
|
||||
window.addEventListener("pagehide", () => pageClosed.abort());
|
||||
|
||||
let refreshInFlight = false;
|
||||
|
||||
// The ten-second refresh init() starts, stopped when the popup moves to the
|
||||
@@ -66,6 +74,7 @@ async function doRefreshAndRender() {
|
||||
state.blockscoutUrl,
|
||||
state.trackedTokens,
|
||||
state.networkId,
|
||||
pageClosed.signal,
|
||||
),
|
||||
]);
|
||||
state.lastBalanceRefresh = Date.now();
|
||||
@@ -87,6 +96,7 @@ async function doRefreshAndRender() {
|
||||
const ctx = {
|
||||
renderWalletList,
|
||||
doRefreshAndRender,
|
||||
pageClosed: pageClosed.signal,
|
||||
showAddWalletView: () => {
|
||||
pushCurrentView();
|
||||
addWallet.show();
|
||||
|
||||
@@ -225,6 +225,9 @@ async function loadHomeTxs(ctx) {
|
||||
homeTxs = merged.slice(0, 25);
|
||||
renderHomeTxList(ctx);
|
||||
} catch (e) {
|
||||
// Cancelled by the popup closing, not failed: see pageClosed in
|
||||
// src/popup/index.js.
|
||||
if (ctx.pageClosed.aborted) return;
|
||||
log.errorf("loadHomeTxs failed:", e.message);
|
||||
const list = $("home-tx-list");
|
||||
if (list) {
|
||||
|
||||
Reference in New Issue
Block a user