From 6ef7f14f4d679cfaf72a92961859be0d14d59afd Mon Sep 17 00:00:00 2001 From: Marcos Caceres Date: Mon, 22 Sep 2025 17:07:54 +1000 Subject: [PATCH 1/2] Handle non-fully-active documents (and destroyed execution contexts) --- index.bs | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/index.bs b/index.bs index 2cc3ce42..ab808254 100644 --- a/index.bs +++ b/index.bs @@ -866,6 +866,44 @@ it is not always *sufficient* to protect users from invasive behaviours, and seeking [meaningful consent](#consent) is also important. +

Handle non-fully-active documents (and destroyed execution contexts)

+ +When an <{iframe}> (or similar) is removed or navigated, +its document stops being [=Document/fully active=] +and its [=ECMAScript/execution contexts=] can get destroyed. +However, references to objects from that document +can remain reachable from other documents +or from other realms. + +Specifications should say what happens both at call time +and after an operation has begun: +otherwise background work may keep running after a page is gone, +UI can hang, and user agents diverge in abort/cleanup behavior. + +If the [=relevant global object=]'s [=associated Document=] +is not [=Document/fully active=] at call time, +then [=throw=], or return [=a promise rejected with=], +with {{InvalidStateError}}. + +If, after starting an asynchronous operation, +that [=associated Document=] becomes non-[=Document/fully active=] +or the [=relevant global object=]'s [=ECMAScript/execution context=] is destroyed, +abort the operation and reject with {{AbortError}}. +If the operation presents UI (e.g., a picker, chooser, or prompt), +dismiss it when the context becomes non-[=Document/fully active=] +and settle with {{AbortError}}. + +When [=queue a task|queueing=] subsequent work +(e.g., for an event, settling a promise, a time-based operation), +include an early exit: +if the [=associated Document=] is not [=Document/fully active=], +gracefully terminate the [=task=]. +Do not rely on garbage collection to define these semantics. + +See also: [[#support-non-fully-active]] for the BFCache case; +most of the same principles apply to detached iframes +and other torn-down [=All Execution Contexts/realms=]. +

Support non-fully active BFCached documents

Specify how your feature behaves @@ -1615,7 +1653,7 @@ Unlike dictionaries, interfaces: (i.e., one can check if it is an `instanceof` a particular class on the global scope), Defining an interface also exposes it on the global scope, allowing for the specification of static methods. -For example, the `canParse()` static method of the URL interface. +For example, the `canParse()` static method of the URL interface. ```JS if (URL.canParse(someURL)) { From 35727b0e30a178b98e494cc9b6804e1cf3139524 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= Date: Tue, 7 Oct 2025 17:28:27 +0800 Subject: [PATCH 2/2] Update index.bs --- index.bs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.bs b/index.bs index ab808254..6f3dca0d 100644 --- a/index.bs +++ b/index.bs @@ -887,7 +887,7 @@ with {{InvalidStateError}}. If, after starting an asynchronous operation, that [=associated Document=] becomes non-[=Document/fully active=] -or the [=relevant global object=]'s [=ECMAScript/execution context=] is destroyed, +or the [=relevant global object=]'s [=ECMAScript/execution context=] is destroyed by script, abort the operation and reject with {{AbortError}}. If the operation presents UI (e.g., a picker, chooser, or prompt), dismiss it when the context becomes non-[=Document/fully active=]