diff --git a/triggers.md b/triggers.md index b0e9667..1846d23 100644 --- a/triggers.md +++ b/triggers.md @@ -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) @@ -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 `` element.