Skip to content

Commit

Permalink
Merge pull request #51 from cloudflare/fix-legacy-url
Browse files Browse the repository at this point in the history
fix: runtime now needs a valid url and not just the path
  • Loading branch information
meddulla committed Jun 10, 2024
2 parents e8d635d + 10b0c0a commit 808f08a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cloudflare/puppeteer",
"version": "0.0.10",
"version": "0.0.11",
"description": "A high-level API to control headless Chrome over the DevTools Protocol for use in Workers",
"keywords": [
"puppeteer",
Expand Down
2 changes: 1 addition & 1 deletion src/common/WorkersWebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class WorkersWebSocketTransport implements ConnectionTransport {
endpoint: BrowserWorker,
sessionid: string
): Promise<WorkersWebSocketTransport> {
const path = `/v1/connectDevtools?browser_session=${sessionid}`;
const path = `https://fake.host/v1/connectDevtools?browser_session=${sessionid}`;
const response = await endpoint.fetch(path, {
headers: {Upgrade: 'websocket'},
});
Expand Down
10 changes: 6 additions & 4 deletions src/puppeteer-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export {BrowserWorker} from './common/BrowserWorker.js';

// initializePuppeteer('puppeteer-core');

const FAKE_HOST = 'https://fake.host';

/* Original singleton and exports
* We redefine below
export const {
Expand Down Expand Up @@ -109,7 +111,7 @@ class PuppeteerWorkers extends Puppeteer {
endpoint: BrowserWorker,
options?: LaunchOptions
): Promise<Browser> {
let acquireUrl = '/v1/acquire';
let acquireUrl = `${FAKE_HOST}/v1/acquire`;
if (options?.keep_alive) {
acquireUrl = `${acquireUrl}?keep_alive=${options.keep_alive}`;
}
Expand All @@ -136,7 +138,7 @@ class PuppeteerWorkers extends Puppeteer {
* @returns List of active sessions
*/
public async sessions(endpoint: BrowserWorker) {
const res = await endpoint.fetch('/v1/sessions');
const res = await endpoint.fetch(`${FAKE_HOST}/v1/sessions`);
const status = res.status;
const text = await res.text();
if (status !== 200) {
Expand All @@ -155,7 +157,7 @@ class PuppeteerWorkers extends Puppeteer {
* @returns List of recent sessions (active and closed)
*/
public async history(endpoint: BrowserWorker) {
const res = await endpoint.fetch('/v1/history');
const res = await endpoint.fetch(`${FAKE_HOST}/v1/history`);
const status = res.status;
const text = await res.text();
if (status !== 200) {
Expand All @@ -174,7 +176,7 @@ class PuppeteerWorkers extends Puppeteer {
* @returns current limits
*/
public async limits(endpoint: BrowserWorker) {
const res = await endpoint.fetch('/v1/limits');
const res = await endpoint.fetch(`${FAKE_HOST}/v1/limits`);
const status = res.status;
const text = await res.text();
if (status !== 200) {
Expand Down

0 comments on commit 808f08a

Please sign in to comment.