diff --git a/puppeteer/wait_for_network.js b/puppeteer/wait_for_network.js new file mode 100644 index 0000000..8f915d6 --- /dev/null +++ b/puppeteer/wait_for_network.js @@ -0,0 +1,42 @@ +// Copyright 2023-2024 Lightpanda (Selecy SAS) +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +'use scrict' + +import puppeteer from 'puppeteer-core'; + +const browserAddress = process.env.BROWSER_ADDRESS ? process.env.BROWSER_ADDRESS : 'ws://127.0.0.1:9222'; +const url = process.env.URL ? process.env.URL : 'https://httpbin.io/xhr/get'; + +// use browserWSEndpoint to pass the Lightpanda's CDP server address. +const browser = await puppeteer.connect({ + browserWSEndpoint: browserAddress, +}); + +// The rest of your script remains the same. +const context = await browser.createBrowserContext(); +const page = await context.newPage(); + +await page.goto(url); +await page.waitForNetworkIdle(); + +const xhr_content = await page.evaluate(() => { return document.querySelector('#response').textContent; }); +const parsed = JSON.parse(xhr_content); +if (parsed.headers['User-Agent'] != 'Lightpanda/1.0') { + console.log(xhr_content); + throw new Error("invalid XHR content"); +} + +await page.close(); +await context.close(); +await browser.disconnect(); diff --git a/runner/main.go b/runner/main.go index f134bad..34fdc2c 100644 --- a/runner/main.go +++ b/runner/main.go @@ -101,6 +101,7 @@ func run(ctx context.Context, args []string, stdout, stderr io.Writer) error { {Bin: "node", Args: []string{"puppeteer/dump.js"}, Env: []string{"URL=http://127.0.0.1:1234/campfire-commerce/"}}, {Bin: "node", Args: []string{"puppeteer/links.js"}, Env: []string{"URL=http://127.0.0.1:1234/campfire-commerce/"}}, {Bin: "node", Args: []string{"puppeteer/click.js"}}, + {Bin: "node", Args: []string{"puppeteer/wait_for_network.js"}}, {Bin: "node", Args: []string{"playwright/connect.js"}}, {Bin: "node", Args: []string{"playwright/cdp.js"}, Env: []string{"RUNS=2"}}, {Bin: "node", Args: []string{"playwright/click.js"}},