diff --git a/.eslintignore b/.eslintignore
index ee10778e..bcf6efa5 100644
--- a/.eslintignore
+++ b/.eslintignore
@@ -1,3 +1,2 @@
third_party/*
-examples/*
utils/doclint/check_public_api/test/
diff --git a/examples/colorwheel.js b/examples/colorwheel.js
index 6c5a006e..bbe3796b 100644
--- a/examples/colorwheel.js
+++ b/examples/colorwheel.js
@@ -14,58 +14,58 @@
* limitations under the License.
*/
-var Browser = require('../lib/Browser');
-var browser = new Browser();
+const Browser = require('../lib/Browser');
+let browser = new Browser();
browser.newPage().then(async page => {
- await page.setViewport({width: 400, height: 400});
- await page.setContent('
');
- await page.evaluate(drawColorWheel);
- await page.screenshot({path: 'colorwheel.png'});
- browser.close();
+ await page.setViewport({width: 400, height: 400});
+ await page.setContent('');
+ await page.evaluate(drawColorWheel);
+ await page.screenshot({path: 'colorwheel.png'});
+ browser.close();
});
function drawColorWheel() {
- var el = document.getElementById('surface'),
- context = el.getContext('2d'),
- width = window.innerWidth,
- height = window.innerHeight,
- cx = width / 2,
- cy = height / 2,
- radius = width / 2.3,
- imageData,
- pixels,
- hue, sat, value,
- i = 0, x, y, rx, ry, d,
- f, g, p, u, v, w, rgb;
+ let el = document.getElementById('surface'),
+ context = el.getContext('2d'),
+ width = window.innerWidth,
+ height = window.innerHeight,
+ cx = width / 2,
+ cy = height / 2,
+ radius = width / 2.3,
+ imageData,
+ pixels,
+ hue, sat,
+ i = 0, x, y, rx, ry, d,
+ f, g, u, v, w;
- el.width = width;
- el.height = height;
- imageData = context.createImageData(width, height);
- pixels = imageData.data;
+ el.width = width;
+ el.height = height;
+ imageData = context.createImageData(width, height);
+ pixels = imageData.data;
- for (y = 0; y < height; y = y + 1) {
- for (x = 0; x < width; x = x + 1, i = i + 4) {
- rx = x - cx;
- ry = y - cy;
- d = rx * rx + ry * ry;
- if (d < radius * radius) {
- hue = 6 * (Math.atan2(ry, rx) + Math.PI) / (2 * Math.PI);
- sat = Math.sqrt(d) / radius;
- g = Math.floor(hue);
- f = hue - g;
- u = 255 * (1 - sat);
- v = 255 * (1 - sat * f);
- w = 255 * (1 - sat * (1 - f));
- pixels[i] = [255, v, u, u, w, 255, 255][g];
- pixels[i + 1] = [w, 255, 255, v, u, u, w][g];
- pixels[i + 2] = [u, u, w, 255, 255, v, u][g];
- pixels[i + 3] = 255;
- }
- }
+ for (y = 0; y < height; y = y + 1) {
+ for (x = 0; x < width; x = x + 1, i = i + 4) {
+ rx = x - cx;
+ ry = y - cy;
+ d = rx * rx + ry * ry;
+ if (d < radius * radius) {
+ hue = 6 * (Math.atan2(ry, rx) + Math.PI) / (2 * Math.PI);
+ sat = Math.sqrt(d) / radius;
+ g = Math.floor(hue);
+ f = hue - g;
+ u = 255 * (1 - sat);
+ v = 255 * (1 - sat * f);
+ w = 255 * (1 - sat * (1 - f));
+ pixels[i] = [255, v, u, u, w, 255, 255][g];
+ pixels[i + 1] = [w, 255, 255, v, u, u, w][g];
+ pixels[i + 2] = [u, u, w, 255, 255, v, u][g];
+ pixels[i + 3] = 255;
+ }
}
+ }
- context.putImageData(imageData, 0, 0);
- document.body.style.backgroundColor = 'white';
- document.body.style.margin = '0px';
+ context.putImageData(imageData, 0, 0);
+ document.body.style.backgroundColor = 'white';
+ document.body.style.margin = '0px';
}
diff --git a/examples/custom-chromium-revision.js b/examples/custom-chromium-revision.js
index 0b4fe462..30485747 100644
--- a/examples/custom-chromium-revision.js
+++ b/examples/custom-chromium-revision.js
@@ -14,23 +14,23 @@
* limitations under the License.
*/
-var Browser = require('../lib/Browser');
-var Downloader = require('../utils/ChromiumDownloader');
+const Browser = require('../lib/Browser');
+const Downloader = require('../utils/ChromiumDownloader');
-var revision = '483012';
+let revision = '483012';
console.log('Downloading custom chromium revision - ' + revision);
-Downloader.downloadRevision(Downloader.currentPlatform(), revision).then(async () => {
- console.log('Done.');
- var executablePath = Downloader.revisionInfo(Downloader.currentPlatform(), revision).executablePath;
- var browser1 = new Browser({ executablePath });
- var browser2 = new Browser();
- var [version1, version2] = await Promise.all([
- browser1.version(),
- browser2.version()
- ]);
- console.log('browser1: ' + version1);
- console.log('browser2: ' + version2);
- browser1.close();
- browser2.close();
+Downloader.downloadRevision(Downloader.currentPlatform(), revision).then(async() => {
+ console.log('Done.');
+ let executablePath = Downloader.revisionInfo(Downloader.currentPlatform(), revision).executablePath;
+ let browser1 = new Browser({ executablePath });
+ let browser2 = new Browser();
+ let [version1, version2] = await Promise.all([
+ browser1.version(),
+ browser2.version()
+ ]);
+ console.log('browser1: ' + version1);
+ console.log('browser2: ' + version2);
+ browser1.close();
+ browser2.close();
});
diff --git a/examples/detectsniff.js b/examples/detectsniff.js
index 6e24ecb3..1085454b 100644
--- a/examples/detectsniff.js
+++ b/examples/detectsniff.js
@@ -14,54 +14,54 @@
* limitations under the License.
*/
-var Browser = require('../lib/Browser');
+const Browser = require('../lib/Browser');
if (process.argv.length < 3) {
- console.log('Usage: detectsniff.js ');
- return;
+ console.log('Usage: detectsniff.js ');
+ return;
}
-var address = process.argv[2];
+let address = process.argv[2];
console.log('Checking ' + address + '...');
-var browser = new Browser();
+let browser = new Browser();
browser.newPage().then(async page => {
- await page.evaluateOnNewDocument(function() {
- (function () {
- var userAgent = window.navigator.userAgent,
- platform = window.navigator.platform;
+ await page.evaluateOnNewDocument(function() {
+ (function() {
+ let userAgent = window.navigator.userAgent,
+ platform = window.navigator.platform;
- window.navigator = {
- appCodeName: 'Mozilla',
- appName: 'Netscape',
- cookieEnabled: false,
- sniffed: false
- };
+ window.navigator = {
+ appCodeName: 'Mozilla',
+ appName: 'Netscape',
+ cookieEnabled: false,
+ sniffed: false
+ };
- window.navigator.__defineGetter__('userAgent', function () {
- window.navigator.sniffed = true;
- return userAgent;
- });
+ window.navigator.__defineGetter__('userAgent', function() {
+ window.navigator.sniffed = true;
+ return userAgent;
+ });
- window.navigator.__defineGetter__('platform', function () {
- window.navigator.sniffed = true;
- return platform;
- });
- })();
- });
- var success = await page.navigate(address);
- if (!success) {
- console.log('FAIL to load the address');
- browser.close();
- return;
- }
- setTimeout(async function () {
- var sniffed = await page.evaluate(() => navigator.sniffed);
- if (sniffed) {
- console.log('The page tried to sniff the user agent.');
- } else {
- console.log('The page did not try to sniff the user agent.');
- }
- browser.close();
- }, 1500);
+ window.navigator.__defineGetter__('platform', function() {
+ window.navigator.sniffed = true;
+ return platform;
+ });
+ })();
+ });
+ let success = await page.navigate(address);
+ if (!success) {
+ console.log('FAIL to load the address');
+ browser.close();
+ return;
+ }
+ setTimeout(async function() {
+ let sniffed = await page.evaluate(() => navigator.sniffed);
+ if (sniffed)
+ console.log('The page tried to sniff the user agent.');
+ else
+ console.log('The page did not try to sniff the user agent.');
+
+ browser.close();
+ }, 1500);
});
diff --git a/examples/features.js b/examples/features.js
index 035dfc23..4f908120 100644
--- a/examples/features.js
+++ b/examples/features.js
@@ -14,43 +14,43 @@
* limitations under the License.
*/
-var path = require('path');
-var Browser = require('../lib/Browser');
-var browser = new Browser();
+const path = require('path');
+const Browser = require('../lib/Browser');
+let browser = new Browser();
browser.newPage().then(async page => {
- var modernizrPath = path.join(__dirname, '../third_party/phantomjs/examples/modernizr.js');
- await page.injectFile(modernizrPath);
- page.on('console', console.log);
- await page.evaluate(detectFeatures);
- browser.close();
+ let modernizrPath = path.join(__dirname, '../third_party/phantomjs/examples/modernizr.js');
+ await page.injectFile(modernizrPath);
+ page.on('console', console.log);
+ await page.evaluate(detectFeatures);
+ browser.close();
});
function detectFeatures() {
- var supported = [], unsupported = [];
- console.log('Detected features (using Modernizr ' + Modernizr._version + '):');
- for (var feature in Modernizr) {
- if (Modernizr.hasOwnProperty(feature)) {
- if (feature[0] !== '_' && typeof Modernizr[feature] !== 'function' &&
+ let supported = [], unsupported = [];
+ console.log('Detected features (using Modernizr ' + Modernizr._version + '):');
+ for (let feature in Modernizr) {
+ if (Modernizr.hasOwnProperty(feature)) {
+ if (feature[0] !== '_' && typeof Modernizr[feature] !== 'function' &&
feature !== 'input' && feature !== 'inputtypes') {
- if (Modernizr[feature]) {
- supported.push(feature);
- } else {
- unsupported.push(feature);
- }
- }
- }
+ if (Modernizr[feature])
+ supported.push(feature);
+ else
+ unsupported.push(feature);
+
+ }
}
+ }
- console.log('');
- console.log('Supported:');
- supported.forEach(function (e) {
- console.log(' ' + e);
- });
+ console.log('');
+ console.log('Supported:');
+ supported.forEach(function(e) {
+ console.log(' ' + e);
+ });
- console.log('');
- console.log('Not supported:');
- unsupported.forEach(function (e) {
- console.log(' ' + e);
- });
+ console.log('');
+ console.log('Not supported:');
+ unsupported.forEach(function(e) {
+ console.log(' ' + e);
+ });
}
diff --git a/examples/loadurlwithoutcss.js b/examples/loadurlwithoutcss.js
index ac2ce48a..f4f1f420 100644
--- a/examples/loadurlwithoutcss.js
+++ b/examples/loadurlwithoutcss.js
@@ -14,25 +14,25 @@
* limitations under the License.
*/
-var Browser = require('../lib/Browser');
+const Browser = require('../lib/Browser');
if (process.argv.length < 3) {
- console.log('Usage: loadurlwithoutcss.js URL');
- return;
+ console.log('Usage: loadurlwithoutcss.js URL');
+ 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 => {
- page.setRequestInterceptor(request => {
- if (request.url.endsWith('.css'))
- request.abort();
- else
- request.continue();
- });
- var success = await page.navigate(address);
- if (!success)
- console.log('Unable to load the address!');
- browser.close();
+ page.setRequestInterceptor(request => {
+ if (request.url.endsWith('.css'))
+ request.abort();
+ else
+ request.continue();
+ });
+ let success = await page.navigate(address);
+ if (!success)
+ console.log('Unable to load the address!');
+ browser.close();
});
diff --git a/examples/openurlwithproxy.js b/examples/openurlwithproxy.js
index 9c241ba9..b12ad454 100644
--- a/examples/openurlwithproxy.js
+++ b/examples/openurlwithproxy.js
@@ -14,29 +14,27 @@
* limitations under the License.
*/
-var Browser = require('../lib/Browser');
+const Browser = require('../lib/Browser');
if (process.argv.length < 5) {
- console.log('Usage: openurlwithproxy.js ');
- return;
+ console.log('Usage: openurlwithproxy.js ');
+ return;
}
-var host = process.argv[2];
-var port = process.argv[3];
-var address = process.argv[4];
+let host = process.argv[2];
+let port = process.argv[3];
+let address = process.argv[4];
-var browser = new Browser({
- args: [
- `--proxy-server=${host}:${port}`;
- ]
+let browser = new Browser({
+ args: [ `--proxy-server=${host}:${port}`]
});
browser.newPage().then(async page => {
- var success = await page.navigate(address);
- if (success) {
- console.log('Page title is ' + (await page.title()));
- } else {
- console.log('FAIL to load the address "' +
+ let success = await page.navigate(address);
+ if (success) {
+ console.log('Page title is ' + (await page.title()));
+ } else {
+ console.log('FAIL to load the address "' +
address + '" using proxy "' + host + ':' + port + '"');
- }
- browser.close();
+ }
+ browser.close();
});
diff --git a/examples/pagecallback.js b/examples/pagecallback.js
index b4df51ed..32edb778 100644
--- a/examples/pagecallback.js
+++ b/examples/pagecallback.js
@@ -14,31 +14,27 @@
* limitations under the License.
*/
-var Browser = require('../lib/Browser');
-var browser = new Browser();
+const Browser = require('../lib/Browser');
+let browser = new Browser();
browser.newPage().then(async page => {
- page.on('console', console.log);
+ page.on('console', console.log);
- await page.setInPageCallback('callPhantom', msg => {
- console.log("Page is saying: '" + msg + "'");
- return "Hello, page";
- });
+ await page.setInPageCallback('callPhantom', msg => {
+ console.log("Page is saying: '" + msg + "'");
+ return 'Hello, page';
+ });
+ await page.evaluate(async function() {
- await page.evaluate(async function() {
+ // Return-value of the "onCallback" handler arrive here
+ let callbackResponse = await window.callPhantom('Hello, driver');
+ console.log("Driver is saying: '" + callbackResponse + "'");
-
- // Return-value of the "onCallback" handler arrive here
- var callbackResponse = await window.callPhantom("Hello, driver");
- console.log("Driver is saying: '" + callbackResponse + "'");
-
-
-
- });
- browser.close();
+ });
+ browser.close();
});
diff --git a/examples/screenshot.js b/examples/screenshot.js
index 35b3581b..c9e72899 100644
--- a/examples/screenshot.js
+++ b/examples/screenshot.js
@@ -18,7 +18,7 @@ const Browser = require('../lib/Browser');
const browser = new Browser();
browser.newPage().then(async page => {
- await page.navigate('http://example.com');
- const screenshot = await page.screenshot({path: 'example.png'});
- browser.close();
+ await page.navigate('http://example.com');
+ await page.screenshot({path: 'example.png'});
+ browser.close();
});
diff --git a/examples/unrandomize.js b/examples/unrandomize.js
index b71884fc..8820c0f1 100644
--- a/examples/unrandomize.js
+++ b/examples/unrandomize.js
@@ -14,20 +14,20 @@
* limitations under the License.
*/
-var Browser = require('../lib/Browser');
-var browser = new Browser();
+const Browser = require('../lib/Browser');
+let browser = new Browser();
browser.newPage().then(async page => {
- await page.evaluateOnNewDocument(function() {
- Math.random = () => 42 / 100;
- });
- var result = await page.navigate('http://ariya.github.com/js/random/');
- if (result) {
- console.log(await page.evaluate(function () {
- return document.getElementById('numbers').textContent;
- }));
- } else {
- console.log('Network error.');
- }
- browser.close();
+ await page.evaluateOnNewDocument(function() {
+ Math.random = () => 42 / 100;
+ });
+ let result = await page.navigate('http://ariya.github.com/js/random/');
+ if (result) {
+ console.log(await page.evaluate(function() {
+ return document.getElementById('numbers').textContent;
+ }));
+ } else {
+ console.log('Network error.');
+ }
+ browser.close();
});