-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: extract the script injection hack to
puppeteer-utils
- introduce a new util module `puppetter-utils` - the mode contains an `addScripts` function to inject script paths to a browser page, annotating the inserted script elements with the `data-ace` attribute. - refactor `checker-chromium` to inject the scripts using this new method. The scripts inserted by Ace are now defined in a single array, easier to read and configure.
- Loading branch information
Showing
2 changed files
with
43 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
async function addScripts(paths, page) { | ||
// BEGIN HACK | ||
// Used to differentiate original `script` elements from the one | ||
// added by Puppeteer. | ||
// FIXME remove this hack when GoogleChrome/puppeteer#1179 is fixed | ||
await page.$$eval('script', (scripts) => { | ||
scripts.forEach(script => script.setAttribute('data-ace-orig', '')); | ||
}); | ||
/* eslint-disable no-restricted-syntax, no-await-in-loop */ | ||
for (const path of paths) { | ||
await page.addScriptTag({ path }); | ||
} | ||
/* eslint-enable no-restricted-syntax, no-await-in-loop */ | ||
// BEGIN HACK | ||
// FIXME remove this hack when GoogleChrome/puppeteer#1179 is fixed | ||
await page.$$eval('script', (scripts) => { | ||
scripts.forEach((script) => { | ||
if (script.hasAttribute('data-ace-orig')) { | ||
script.removeAttribute('data-ace-orig'); | ||
} else { | ||
script.setAttribute('data-ace', ''); | ||
} | ||
}); | ||
}); | ||
// END HACK | ||
} | ||
|
||
module.exports = { | ||
addScripts, | ||
}; |