File tree Expand file tree Collapse file tree
plugins/optimization-detective Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,13 +26,25 @@ async function load() {
2626 } ) ;
2727 }
2828
29- const data = JSON . parse (
30- /** @type {HTMLElement } */ (
31- document . getElementById ( 'optimization-detective-detect-args' )
32- ) . textContent ?? ''
29+ const argsScript = document . getElementById (
30+ 'optimization-detective-detect-args'
3331 ) ;
32+ if ( ! ( argsScript instanceof HTMLScriptElement ) ) {
33+ throw new Error ( 'Missing: SCRIPT#optimization-detective-detect-args' ) ;
34+ }
35+ const data = JSON . parse ( argsScript . textContent ) ;
36+ if (
37+ ! Array . isArray ( data ) ||
38+ data . length !== 2 ||
39+ 'string' !== typeof data [ 0 ] ||
40+ 'object' !== typeof data [ 1 ]
41+ ) {
42+ throw new Error (
43+ 'SCRIPT#optimization-detective-detect-args is not [ string, object ]'
44+ ) ;
45+ }
3446
35- const detectSrc = /** @type { string } */ data [ 0 ] ;
47+ const detectSrc = data [ 0 ] ;
3648 const detectArgs =
3749 /** @type {import("./detect.js").DetectFunctionArgs } */ data [ 1 ] ;
3850 const detect = /** @type {import("./detect.js").DetectFunction } */ (
You can’t perform that action at this time.
0 commit comments