Skip to content

Should we "check if we can run script" before calling callbacks? #993

@domenic

Description

@domenic

Most places in HTML that use prepare to run script call check if we can run script beforehand, and bail out if you can't:

However, Web IDL notably does not! See:

This is important because the first step in "check if we can run the script" is to return false if the given realm (in this case, the realm of the callback or of the object) comes from a non-fully-active document, e.g. a detached iframe or a bfcached page.

Chrome seems to include such a "check if we can run script" check for Web IDL callbacks: see https://jsfiddle.net/shaseley/w4nsq2oj/7/ which runs the task in Firefox and Safari but does not run the task in Chrome. Discovered by @shaseley @natechapin.

Worse, https://jsfiddle.net/n04m3jpo/ shows a variant with promise handlers (instead of setTimeout's Web IDL callbacks) where Chrome and Safari do run the promise handler, and Firefox does not.

(On the spec side, I think we cargo-culted the "check if we can run script" check into HostEnqueueFinalizationRegistryCleanupJob and HostEnqueuePromiseJob without testing, because I thought it was about the user disabling scripting, and I forgot it was also about non-fully-active documents.)

My instinct is that we should be uniform here and not run the handler in any cases. /cc @smaug---- @rakina for bfcache connection, @syg for promise/finalization registry connection.

Related: whatwg/html#2621

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions