Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 11 additions & 13 deletions node-playwright-camoufox/firefox_test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,27 @@
const { launchPlaywright } = require('crawlee');
const playwright = require('playwright');
const { launchOptions: camoufoxLaunchOptions } = require('camoufox-js');

const testPageLoading = async (browser) => {
const page = await browser.newPage();
await page.goto('http://www.example.com');
const pageTitle = await page.title();
if (pageTitle !== 'Example Domain') {
throw new Error(`Playwright+Firefox test failed - returned title "${pageTitle}"" !== "Example Domain"`);
throw new Error(`Playwright+Firefox test failed - returned title "${pageTitle}" !== "Example Domain"`);
}
};

const testFirefox = async (launchOptions) => {
const launchContext = {
launcher: require('playwright').firefox,
launchOptions: await camoufoxLaunchOptions({
...launchOptions,
}),
};
const testFirefox = async (launchOptions = {}) => {
const options = await camoufoxLaunchOptions({ ...launchOptions });

console.log(`Testing Playwright with Firefox`, launchContext.launchOptions);
console.log('Testing Playwright with Camoufox', options);

const browser = await launchPlaywright(launchContext);
const browser = await playwright.firefox.launch(options);

await testPageLoading(browser);
await browser.close();
try {
await testPageLoading(browser);
} finally {
await browser.close();
}
};

module.exports = testFirefox;
36 changes: 22 additions & 14 deletions node-playwright-camoufox/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,31 @@ For more information, see https://docs.apify.com/actors/development/source-code#
`);
console.log('Testing Docker image...');

const { Actor } = require('apify');
const { getMemoryInfo } = require('crawlee');
const testFirefox = require('./firefox_test');
// `apify` is optional: the image no longer preinstalls it.
let Actor;
try {
({ Actor } = require('apify'));
} catch {
Actor = undefined;
}

Actor.main(async () => {
// Sanity test browsers.
const testFirefox = require('./firefox_test');

// Try to use full Firefox headless
const run = async () => {
// Camoufox (Firefox) headless
await testFirefox({ headless: true });

// Try to use full Firefox with XVFB
// Camoufox (Firefox) with XVFB (headful)
await testFirefox({ headless: false });

// Try to use playwright default
await testFirefox({ executablePath: undefined });
await testFirefox({ executablePath: process.env.APIFY_DEFAULT_BROWSER_PATH });

// Test that "ps" command is available, sometimes it was missing in official Node builds
await getMemoryInfo();
});
console.log('... test PASSED');
};

if (Actor) {
Actor.main(run);
} else {
run().catch((error) => {
console.error(error);
process.exitCode = 1;
});
}
12 changes: 1 addition & 11 deletions node-playwright-camoufox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,9 @@
"start": "node main.js"
},
"dependencies": {
"apify": "APIFY_VERSION",
"camoufox-js": "CAMOUFOX_VERSION",
"crawlee": "CRAWLEE_VERSION",
"impit": "latest",
"playwright": "PLAYWRIGHT_VERSION",
"typescript": "^5.4.3"
},
"overrides": {
"apify": {
"@crawlee/core": "CRAWLEE_VERSION",
"@crawlee/types": "CRAWLEE_VERSION",
"@crawlee/utils": "CRAWLEE_VERSION"
}
"playwright": "PLAYWRIGHT_VERSION"
},
"repository": {}
}
20 changes: 11 additions & 9 deletions node-playwright-chrome/chrome_test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
const { launchPlaywright } = require('crawlee');
const playwright = require('playwright');

const testPageLoading = async (browser) => {
const page = await browser.newPage();
await page.goto('http://www.example.com');
const pageTitle = await page.title();
if (pageTitle !== 'Example Domain') {
throw new Error(`Playwright+Chrome test failed - returned title "${pageTitle}"" !== "Example Domain"`);
throw new Error(`Playwright+Chrome test failed - returned title "${pageTitle}" !== "Example Domain"`);
}
};

const testChrome = async (launchOptions) => {
const launchContext = { useChrome: true, launchOptions };
const testChrome = async (launchOptions = {}) => {
console.log('Testing Playwright with Chrome', launchOptions);

console.log(`Testing Playwright with Chrome`, launchContext);
const browser = await playwright.chromium.launch({ channel: 'chrome', ...launchOptions });

const browser = await launchPlaywright(launchContext);

await testPageLoading(browser);
await browser.close();
try {
await testPageLoading(browser);
} finally {
await browser.close();
}
};

module.exports = {
testChrome,
testPageLoading,
};
42 changes: 22 additions & 20 deletions node-playwright-chrome/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,29 +11,31 @@ For more information, see https://docs.apify.com/actors/development/source-code#
`);
console.log('Testing Docker image...');

const { Actor } = require('apify');
const { launchPlaywright, getMemoryInfo } = require('crawlee');
const { testChrome } = require('./chrome_test');

Actor.main(async () => {
// Sanity test browsers.
// We need --no-sandbox, because even though the build is running on GitHub, the test is running in Docker.
const launchOptions = { headless: true, args: ['--no-sandbox'] };
const launchContext = { launchOptions };
// `apify` is optional: the image no longer preinstalls it.
let Actor;
try {
({ Actor } = require('apify'));
} catch {
Actor = undefined;
}

const browser = await launchPlaywright(launchContext);
await browser.close();
const { testChrome } = require('./chrome_test');

// Try to use full Chrome headless
const run = async () => {
// Full Chrome headless
await testChrome({ headless: true });

// Try to use full Chrome with XVFB
// Full Chrome with XVFB (headful)
await testChrome({ headless: false });

// Try to use playwright default
await testChrome({ executablePath: undefined });
await testChrome({ executablePath: process.env.APIFY_DEFAULT_BROWSER_PATH });

// Test that "ps" command is available, sometimes it was missing in official Node builds
await getMemoryInfo();
});
console.log('... test PASSED');
};

if (Actor) {
Actor.main(run);
} else {
run().catch((error) => {
console.error(error);
process.exitCode = 1;
});
}
12 changes: 1 addition & 11 deletions node-playwright-chrome/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@
"start": "node main.js"
},
"dependencies": {
"apify": "APIFY_VERSION",
"crawlee": "CRAWLEE_VERSION",
"playwright-chromium": "PLAYWRIGHT_VERSION",
"typescript": "^5.4.3"
},
"overrides": {
"apify": {
"@crawlee/core": "CRAWLEE_VERSION",
"@crawlee/types": "CRAWLEE_VERSION",
"@crawlee/utils": "CRAWLEE_VERSION"
}
"playwright-chromium": "PLAYWRIGHT_VERSION"
},
"repository": {}
}
22 changes: 10 additions & 12 deletions node-playwright-firefox/firefox_test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
const { launchPlaywright } = require('crawlee');
const playwright = require('playwright');

const testPageLoading = async (browser) => {
const page = await browser.newPage();
await page.goto('http://www.example.com');
const pageTitle = await page.title();
if (pageTitle !== 'Example Domain') {
throw new Error(`Playwright+Firefox test failed - returned title "${pageTitle}"" !== "Example Domain"`);
throw new Error(`Playwright+Firefox test failed - returned title "${pageTitle}" !== "Example Domain"`);
}
};

const testFirefox = async (launchOptions) => {
const launchContext = {
launcher: require('playwright').firefox,
launchOptions,
};
const testFirefox = async (launchOptions = {}) => {
console.log('Testing Playwright with Firefox', launchOptions);

console.log(`Testing Playwright with Firefox`, launchOptions);
const browser = await playwright.firefox.launch(launchOptions);

const browser = await launchPlaywright(launchContext);

await testPageLoading(browser);
await browser.close();
try {
await testPageLoading(browser);
} finally {
await browser.close();
}
};

module.exports = testFirefox;
36 changes: 22 additions & 14 deletions node-playwright-firefox/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,31 @@ For more information, see https://docs.apify.com/actors/development/source-code#
`);
console.log('Testing Docker image...');

const { Actor } = require('apify');
const { getMemoryInfo } = require('crawlee');
const testFirefox = require('./firefox_test');
// `apify` is optional: the image no longer preinstalls it.
let Actor;
try {
({ Actor } = require('apify'));
} catch {
Actor = undefined;
}

Actor.main(async () => {
// Sanity test browsers.
const testFirefox = require('./firefox_test');

// Try to use full Firefox headless
const run = async () => {
// Full Firefox headless
await testFirefox({ headless: true });

// Try to use full Firefox with XVFB
// Full Firefox with XVFB (headful)
await testFirefox({ headless: false });

// Try to use playwright default
await testFirefox({ executablePath: undefined });
await testFirefox({ executablePath: process.env.APIFY_DEFAULT_BROWSER_PATH });

// Test that "ps" command is available, sometimes it was missing in official Node builds
await getMemoryInfo();
});
console.log('... test PASSED');
};

if (Actor) {
Actor.main(run);
} else {
run().catch((error) => {
console.error(error);
process.exitCode = 1;
});
}
12 changes: 1 addition & 11 deletions node-playwright-firefox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@
"start": "node main.js"
},
"dependencies": {
"apify": "APIFY_VERSION",
"crawlee": "CRAWLEE_VERSION",
"playwright-firefox": "PLAYWRIGHT_VERSION",
"typescript": "^5.4.3"
},
"overrides": {
"apify": {
"@crawlee/core": "CRAWLEE_VERSION",
"@crawlee/types": "CRAWLEE_VERSION",
"@crawlee/utils": "CRAWLEE_VERSION"
}
"playwright-firefox": "PLAYWRIGHT_VERSION"
},
"repository": {}
}
36 changes: 22 additions & 14 deletions node-playwright-webkit/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,31 @@ For more information, see https://docs.apify.com/actors/development/source-code#
`);
console.log('Testing Docker image...');

const { Actor } = require('apify');
const { getMemoryInfo } = require('crawlee');
const testWebkit = require('./webkit_test');
// `apify` is optional: the image no longer preinstalls it.
let Actor;
try {
({ Actor } = require('apify'));
} catch {
Actor = undefined;
}

Actor.main(async () => {
// Sanity test browsers.
const testWebkit = require('./webkit_test');

// Try to use full Webkit headless
const run = async () => {
// Full Webkit headless
await testWebkit({ headless: true });

// Try to use full Webkit with XVFB
// Full Webkit with XVFB (headful)
await testWebkit({ headless: false });

// Try to use playwright default
await testWebkit({ executablePath: undefined });
await testWebkit({ executablePath: process.env.APIFY_DEFAULT_BROWSER_PATH });

// Test that "ps" command is available, sometimes it was missing in official Node builds
await getMemoryInfo();
});
console.log('... test PASSED');
};

if (Actor) {
Actor.main(run);
} else {
run().catch((error) => {
console.error(error);
process.exitCode = 1;
});
}
12 changes: 1 addition & 11 deletions node-playwright-webkit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,7 @@
"start": "node main.js"
},
"dependencies": {
"apify": "APIFY_VERSION",
"crawlee": "CRAWLEE_VERSION",
"playwright-webkit": "PLAYWRIGHT_VERSION",
"typescript": "^5.4.3"
},
"overrides": {
"apify": {
"@crawlee/core": "CRAWLEE_VERSION",
"@crawlee/types": "CRAWLEE_VERSION",
"@crawlee/utils": "CRAWLEE_VERSION"
}
"playwright-webkit": "PLAYWRIGHT_VERSION"
},
"repository": {}
}
Loading
Loading