Inject jQuery into Puppeteer page
I have used page.addScriptTag
to inject js
files.
...
await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.2.1.min.js'})
...
page.addScriptTag - documentation
Working example using puppeteer: 0.12.0
import { launch } from 'puppeteer'
(async () => {
const browser = await launch({headless: false});
const page = await browser.newPage();
await page.goto('https://example.com', {waitUntil: 'networkidle'});
await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.2.1.min.js'});
await page.close();
await browser.close();
})();
For those looking to inject a local copy of jQuery:
await page.addScriptTag({path: require.resolve('jquery')})