Skip to content

Commit

Permalink
Feature detection using HTMLScriptElement.supports()
Browse files Browse the repository at this point in the history
The HTMLScriptElement.supports() method was introduced by whatwg/html#7008.
HTMLScriptElement.supports('speculationrules') must return true when supported.
  • Loading branch information
horo-t committed Sep 21, 2021
1 parent dc490cd commit d08b9e7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ The existence of web-facing triggers doesn't necessarily preclude the user agent
- [Extension: Handler URLs](#extension-handler-urls)
- [Proposed Processing Model](#proposed-processing-model)
- [Developer Tooling](#developer-tooling)
- [Feature detection](#feature-detection)
- [Alternatives considered](#alternatives-considered)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->
Expand Down Expand Up @@ -160,6 +161,30 @@ It will likely be useful to surface in developer tools what rules and URLs have

This information and control is important because otherwise it may be difficult to validate correct behavior as it would otherwise depend on heuristics unknown to the author. Similarly testing tools such as [WebDriver][webdriver] should likely permit overriding the user agent's selection of which valid speculations to execute.

### Feature detection

If the browser supports [HTMLScriptElement](https://html.spec.whatwg.org/multipage/scripting.html#htmlscriptelement)'s
[supports(type)](https://html.spec.whatwg.org/multipage/scripting.html#dom-script-supports) method,
`HTMLScriptElement.supports('speculationrules')` must return true.

```js
if (HTMLScriptElement.supports && HTMLScriptElement.supports('speculationrules')) {
console.log('Your browser supports speculationrules.');
}
```

#### Monkeypatch HTMLScriptElement.supports() method in HTML spec

In the HTML spec's [HTMLScriptElement](https://html.spec.whatwg.org/multipage/scripting.html#htmlscriptelement)'s
[supports(type)](https://html.spec.whatwg.org/multipage/scripting.html#dom-script-supports) method, before

> 3. Return false.
add the following step:

3. If type is "`speculationrules`", then return true.


## Alternatives considered

The obvious alternative is to extend the `<link>` element.
Expand Down

0 comments on commit d08b9e7

Please sign in to comment.