mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
parent
c32df08e4c
commit
e6d8fca7cd
@ -1,3 +1,2 @@
|
|||||||
third_party/*
|
third_party/*
|
||||||
examples/*
|
|
||||||
utils/doclint/check_public_api/test/
|
utils/doclint/check_public_api/test/
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Browser = require('../lib/Browser');
|
const Browser = require('../lib/Browser');
|
||||||
var browser = new Browser();
|
let browser = new Browser();
|
||||||
|
|
||||||
browser.newPage().then(async page => {
|
browser.newPage().then(async page => {
|
||||||
await page.setViewport({width: 400, height: 400});
|
await page.setViewport({width: 400, height: 400});
|
||||||
@ -26,7 +26,7 @@ browser.newPage().then(async page => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function drawColorWheel() {
|
function drawColorWheel() {
|
||||||
var el = document.getElementById('surface'),
|
let el = document.getElementById('surface'),
|
||||||
context = el.getContext('2d'),
|
context = el.getContext('2d'),
|
||||||
width = window.innerWidth,
|
width = window.innerWidth,
|
||||||
height = window.innerHeight,
|
height = window.innerHeight,
|
||||||
@ -35,9 +35,9 @@ function drawColorWheel() {
|
|||||||
radius = width / 2.3,
|
radius = width / 2.3,
|
||||||
imageData,
|
imageData,
|
||||||
pixels,
|
pixels,
|
||||||
hue, sat, value,
|
hue, sat,
|
||||||
i = 0, x, y, rx, ry, d,
|
i = 0, x, y, rx, ry, d,
|
||||||
f, g, p, u, v, w, rgb;
|
f, g, u, v, w;
|
||||||
|
|
||||||
el.width = width;
|
el.width = width;
|
||||||
el.height = height;
|
el.height = height;
|
||||||
|
@ -14,17 +14,17 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Browser = require('../lib/Browser');
|
const Browser = require('../lib/Browser');
|
||||||
var Downloader = require('../utils/ChromiumDownloader');
|
const Downloader = require('../utils/ChromiumDownloader');
|
||||||
|
|
||||||
var revision = '483012';
|
let revision = '483012';
|
||||||
console.log('Downloading custom chromium revision - ' + revision);
|
console.log('Downloading custom chromium revision - ' + revision);
|
||||||
Downloader.downloadRevision(Downloader.currentPlatform(), revision).then(async () => {
|
Downloader.downloadRevision(Downloader.currentPlatform(), revision).then(async() => {
|
||||||
console.log('Done.');
|
console.log('Done.');
|
||||||
var executablePath = Downloader.revisionInfo(Downloader.currentPlatform(), revision).executablePath;
|
let executablePath = Downloader.revisionInfo(Downloader.currentPlatform(), revision).executablePath;
|
||||||
var browser1 = new Browser({ executablePath });
|
let browser1 = new Browser({ executablePath });
|
||||||
var browser2 = new Browser();
|
let browser2 = new Browser();
|
||||||
var [version1, version2] = await Promise.all([
|
let [version1, version2] = await Promise.all([
|
||||||
browser1.version(),
|
browser1.version(),
|
||||||
browser2.version()
|
browser2.version()
|
||||||
]);
|
]);
|
||||||
|
@ -14,21 +14,21 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Browser = require('../lib/Browser');
|
const Browser = require('../lib/Browser');
|
||||||
|
|
||||||
if (process.argv.length < 3) {
|
if (process.argv.length < 3) {
|
||||||
console.log('Usage: detectsniff.js <some URL>');
|
console.log('Usage: detectsniff.js <some URL>');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var address = process.argv[2];
|
let address = process.argv[2];
|
||||||
console.log('Checking ' + address + '...');
|
console.log('Checking ' + address + '...');
|
||||||
|
|
||||||
var browser = new Browser();
|
let browser = new Browser();
|
||||||
browser.newPage().then(async page => {
|
browser.newPage().then(async page => {
|
||||||
await page.evaluateOnNewDocument(function() {
|
await page.evaluateOnNewDocument(function() {
|
||||||
(function () {
|
(function() {
|
||||||
var userAgent = window.navigator.userAgent,
|
let userAgent = window.navigator.userAgent,
|
||||||
platform = window.navigator.platform;
|
platform = window.navigator.platform;
|
||||||
|
|
||||||
window.navigator = {
|
window.navigator = {
|
||||||
@ -38,30 +38,30 @@ browser.newPage().then(async page => {
|
|||||||
sniffed: false
|
sniffed: false
|
||||||
};
|
};
|
||||||
|
|
||||||
window.navigator.__defineGetter__('userAgent', function () {
|
window.navigator.__defineGetter__('userAgent', function() {
|
||||||
window.navigator.sniffed = true;
|
window.navigator.sniffed = true;
|
||||||
return userAgent;
|
return userAgent;
|
||||||
});
|
});
|
||||||
|
|
||||||
window.navigator.__defineGetter__('platform', function () {
|
window.navigator.__defineGetter__('platform', function() {
|
||||||
window.navigator.sniffed = true;
|
window.navigator.sniffed = true;
|
||||||
return platform;
|
return platform;
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
});
|
});
|
||||||
var success = await page.navigate(address);
|
let success = await page.navigate(address);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
console.log('FAIL to load the address');
|
console.log('FAIL to load the address');
|
||||||
browser.close();
|
browser.close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTimeout(async function () {
|
setTimeout(async function() {
|
||||||
var sniffed = await page.evaluate(() => navigator.sniffed);
|
let sniffed = await page.evaluate(() => navigator.sniffed);
|
||||||
if (sniffed) {
|
if (sniffed)
|
||||||
console.log('The page tried to sniff the user agent.');
|
console.log('The page tried to sniff the user agent.');
|
||||||
} else {
|
else
|
||||||
console.log('The page did not try to sniff the user agent.');
|
console.log('The page did not try to sniff the user agent.');
|
||||||
}
|
|
||||||
browser.close();
|
browser.close();
|
||||||
}, 1500);
|
}, 1500);
|
||||||
});
|
});
|
||||||
|
@ -14,12 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var path = require('path');
|
const path = require('path');
|
||||||
var Browser = require('../lib/Browser');
|
const Browser = require('../lib/Browser');
|
||||||
var browser = new Browser();
|
let browser = new Browser();
|
||||||
|
|
||||||
browser.newPage().then(async page => {
|
browser.newPage().then(async page => {
|
||||||
var modernizrPath = path.join(__dirname, '../third_party/phantomjs/examples/modernizr.js');
|
let modernizrPath = path.join(__dirname, '../third_party/phantomjs/examples/modernizr.js');
|
||||||
await page.injectFile(modernizrPath);
|
await page.injectFile(modernizrPath);
|
||||||
page.on('console', console.log);
|
page.on('console', console.log);
|
||||||
await page.evaluate(detectFeatures);
|
await page.evaluate(detectFeatures);
|
||||||
@ -27,30 +27,30 @@ browser.newPage().then(async page => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
function detectFeatures() {
|
function detectFeatures() {
|
||||||
var supported = [], unsupported = [];
|
let supported = [], unsupported = [];
|
||||||
console.log('Detected features (using Modernizr ' + Modernizr._version + '):');
|
console.log('Detected features (using Modernizr ' + Modernizr._version + '):');
|
||||||
for (var feature in Modernizr) {
|
for (let feature in Modernizr) {
|
||||||
if (Modernizr.hasOwnProperty(feature)) {
|
if (Modernizr.hasOwnProperty(feature)) {
|
||||||
if (feature[0] !== '_' && typeof Modernizr[feature] !== 'function' &&
|
if (feature[0] !== '_' && typeof Modernizr[feature] !== 'function' &&
|
||||||
feature !== 'input' && feature !== 'inputtypes') {
|
feature !== 'input' && feature !== 'inputtypes') {
|
||||||
if (Modernizr[feature]) {
|
if (Modernizr[feature])
|
||||||
supported.push(feature);
|
supported.push(feature);
|
||||||
} else {
|
else
|
||||||
unsupported.push(feature);
|
unsupported.push(feature);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('Supported:');
|
console.log('Supported:');
|
||||||
supported.forEach(function (e) {
|
supported.forEach(function(e) {
|
||||||
console.log(' ' + e);
|
console.log(' ' + e);
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('');
|
console.log('');
|
||||||
console.log('Not supported:');
|
console.log('Not supported:');
|
||||||
unsupported.forEach(function (e) {
|
unsupported.forEach(function(e) {
|
||||||
console.log(' ' + e);
|
console.log(' ' + e);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Browser = require('../lib/Browser');
|
const Browser = require('../lib/Browser');
|
||||||
|
|
||||||
if (process.argv.length < 3) {
|
if (process.argv.length < 3) {
|
||||||
console.log('Usage: loadurlwithoutcss.js URL');
|
console.log('Usage: loadurlwithoutcss.js URL');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var address = process.argv[2];
|
let address = process.argv[2];
|
||||||
|
|
||||||
var browser = new Browser({headless: false});
|
let browser = new Browser({headless: false});
|
||||||
browser.newPage().then(async page => {
|
browser.newPage().then(async page => {
|
||||||
page.setRequestInterceptor(request => {
|
page.setRequestInterceptor(request => {
|
||||||
if (request.url.endsWith('.css'))
|
if (request.url.endsWith('.css'))
|
||||||
@ -31,7 +31,7 @@ browser.newPage().then(async page => {
|
|||||||
else
|
else
|
||||||
request.continue();
|
request.continue();
|
||||||
});
|
});
|
||||||
var success = await page.navigate(address);
|
let success = await page.navigate(address);
|
||||||
if (!success)
|
if (!success)
|
||||||
console.log('Unable to load the address!');
|
console.log('Unable to load the address!');
|
||||||
browser.close();
|
browser.close();
|
||||||
|
@ -14,24 +14,22 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Browser = require('../lib/Browser');
|
const Browser = require('../lib/Browser');
|
||||||
|
|
||||||
if (process.argv.length < 5) {
|
if (process.argv.length < 5) {
|
||||||
console.log('Usage: openurlwithproxy.js <proxyHost> <proxyPort> <URL>');
|
console.log('Usage: openurlwithproxy.js <proxyHost> <proxyPort> <URL>');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var host = process.argv[2];
|
let host = process.argv[2];
|
||||||
var port = process.argv[3];
|
let port = process.argv[3];
|
||||||
var address = process.argv[4];
|
let address = process.argv[4];
|
||||||
|
|
||||||
var browser = new Browser({
|
let browser = new Browser({
|
||||||
args: [
|
args: [ `--proxy-server=${host}:${port}`]
|
||||||
`--proxy-server=${host}:${port}`;
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
browser.newPage().then(async page => {
|
browser.newPage().then(async page => {
|
||||||
var success = await page.navigate(address);
|
let success = await page.navigate(address);
|
||||||
if (success) {
|
if (success) {
|
||||||
console.log('Page title is ' + (await page.title()));
|
console.log('Page title is ' + (await page.title()));
|
||||||
} else {
|
} else {
|
||||||
|
@ -14,8 +14,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Browser = require('../lib/Browser');
|
const Browser = require('../lib/Browser');
|
||||||
var browser = new Browser();
|
let browser = new Browser();
|
||||||
|
|
||||||
browser.newPage().then(async page => {
|
browser.newPage().then(async page => {
|
||||||
page.on('console', console.log);
|
page.on('console', console.log);
|
||||||
@ -23,22 +23,18 @@ browser.newPage().then(async page => {
|
|||||||
|
|
||||||
await page.setInPageCallback('callPhantom', msg => {
|
await page.setInPageCallback('callPhantom', msg => {
|
||||||
console.log("Page is saying: '" + msg + "'");
|
console.log("Page is saying: '" + msg + "'");
|
||||||
return "Hello, page";
|
return 'Hello, page';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await page.evaluate(async function() {
|
await page.evaluate(async function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Return-value of the "onCallback" handler arrive here
|
// Return-value of the "onCallback" handler arrive here
|
||||||
var callbackResponse = await window.callPhantom("Hello, driver");
|
let callbackResponse = await window.callPhantom('Hello, driver');
|
||||||
console.log("Driver is saying: '" + callbackResponse + "'");
|
console.log("Driver is saying: '" + callbackResponse + "'");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
browser.close();
|
browser.close();
|
||||||
});
|
});
|
||||||
|
@ -19,6 +19,6 @@ const browser = new Browser();
|
|||||||
|
|
||||||
browser.newPage().then(async page => {
|
browser.newPage().then(async page => {
|
||||||
await page.navigate('http://example.com');
|
await page.navigate('http://example.com');
|
||||||
const screenshot = await page.screenshot({path: 'example.png'});
|
await page.screenshot({path: 'example.png'});
|
||||||
browser.close();
|
browser.close();
|
||||||
});
|
});
|
||||||
|
@ -14,16 +14,16 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Browser = require('../lib/Browser');
|
const Browser = require('../lib/Browser');
|
||||||
var browser = new Browser();
|
let browser = new Browser();
|
||||||
|
|
||||||
browser.newPage().then(async page => {
|
browser.newPage().then(async page => {
|
||||||
await page.evaluateOnNewDocument(function() {
|
await page.evaluateOnNewDocument(function() {
|
||||||
Math.random = () => 42 / 100;
|
Math.random = () => 42 / 100;
|
||||||
});
|
});
|
||||||
var result = await page.navigate('http://ariya.github.com/js/random/');
|
let result = await page.navigate('http://ariya.github.com/js/random/');
|
||||||
if (result) {
|
if (result) {
|
||||||
console.log(await page.evaluate(function () {
|
console.log(await page.evaluate(function() {
|
||||||
return document.getElementById('numbers').textContent;
|
return document.getElementById('numbers').textContent;
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user