download-browser.js
This commit is contained in:
parent
b3ea94a4d7
commit
1d884c5a52
|
|
@ -10,8 +10,11 @@ lib/injected/
|
||||||
!lib/**/*.d.ts
|
!lib/**/*.d.ts
|
||||||
!index.d.ts
|
!index.d.ts
|
||||||
|
|
||||||
# root for "playwright" package
|
# used for npm install scripts
|
||||||
|
!download-browser.js
|
||||||
|
|
||||||
|
# root for "playwright-core" package
|
||||||
!index.js
|
!index.js
|
||||||
|
|
||||||
# root for "playwright/web"
|
# root for "playwright-core/web"
|
||||||
!web.js
|
!web.js
|
||||||
|
|
|
||||||
60
download-browser.js
Normal file
60
download-browser.js
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
async function downloadBrowser(browser) {
|
||||||
|
const playwright = require('.')[browser];
|
||||||
|
let progressBar = null;
|
||||||
|
let lastDownloadedBytes = 0;
|
||||||
|
function onProgress(downloadedBytes, totalBytes) {
|
||||||
|
if (!progressBar) {
|
||||||
|
const ProgressBar = require('progress');
|
||||||
|
progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
|
||||||
|
complete: '=',
|
||||||
|
incomplete: ' ',
|
||||||
|
width: 20,
|
||||||
|
total: totalBytes,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const delta = downloadedBytes - lastDownloadedBytes;
|
||||||
|
lastDownloadedBytes = downloadedBytes;
|
||||||
|
progressBar.tick(delta);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fetcher = playwright._createBrowserFetcher();
|
||||||
|
const revisionInfo = fetcher.revisionInfo();
|
||||||
|
// Do nothing if the revision is already downloaded.
|
||||||
|
if (revisionInfo.local)
|
||||||
|
return revisionInfo;
|
||||||
|
await fetcher.download(revisionInfo.revision, onProgress);
|
||||||
|
logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`);
|
||||||
|
return revisionInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function toMegabytes(bytes) {
|
||||||
|
const mb = bytes / 1024 / 1024;
|
||||||
|
return `${Math.round(mb * 10) / 10} Mb`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function logPolitely(toBeLogged) {
|
||||||
|
const logLevel = process.env.npm_config_loglevel;
|
||||||
|
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1;
|
||||||
|
|
||||||
|
if (!logLevelDisplay)
|
||||||
|
console.log(toBeLogged);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {downloadBrowser};
|
||||||
|
|
@ -18,78 +18,46 @@
|
||||||
// This file is only run when someone clones the github repo for development
|
// This file is only run when someone clones the github repo for development
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
console.log('Building playwright...');
|
||||||
require('child_process').execSync('npm run build', {
|
require('child_process').execSync('npm run build', {
|
||||||
stdio: 'ignore'
|
stdio: 'ignore'
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
|
const {downloadBrowser} = require('./download-browser');
|
||||||
|
|
||||||
(async function() {
|
(async function() {
|
||||||
const protocolGenerator = require('./utils/protocol-types-generator');
|
const protocolGenerator = require('./utils/protocol-types-generator');
|
||||||
try {
|
try {
|
||||||
const chromeRevision = await downloadBrowser('chromium', require('./index').chromium);
|
const chromeRevision = await downloadAndCleanup('chromium');
|
||||||
await protocolGenerator.generateChromiunProtocol(chromeRevision);
|
await protocolGenerator.generateChromiunProtocol(chromeRevision);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e.message);
|
console.warn(e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const firefoxRevision = await downloadBrowser('firefox', require('./index').firefox);
|
const firefoxRevision = await downloadAndCleanup('firefox');
|
||||||
await protocolGenerator.generateFirefoxProtocol(firefoxRevision);
|
await protocolGenerator.generateFirefoxProtocol(firefoxRevision);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e.message);
|
console.warn(e.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const webkitRevision = await downloadBrowser('webkit', require('./index').webkit);
|
const webkitRevision = await downloadAndCleanup('webkit');
|
||||||
await protocolGenerator.generateWebKitProtocol(webkitRevision);
|
await protocolGenerator.generateWebKitProtocol(webkitRevision);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e.message);
|
console.warn(e.message);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
async function downloadBrowser(browser, playwright) {
|
async function downloadAndCleanup(browser) {
|
||||||
let progressBar = null;
|
const revisionInfo = await downloadBrowser(browser);
|
||||||
let lastDownloadedBytes = 0;
|
|
||||||
function onProgress(downloadedBytes, totalBytes) {
|
|
||||||
if (!progressBar) {
|
|
||||||
const ProgressBar = require('progress');
|
|
||||||
progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
|
|
||||||
complete: '=',
|
|
||||||
incomplete: ' ',
|
|
||||||
width: 20,
|
|
||||||
total: totalBytes,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const delta = downloadedBytes - lastDownloadedBytes;
|
|
||||||
lastDownloadedBytes = downloadedBytes;
|
|
||||||
progressBar.tick(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetcher = playwright._createBrowserFetcher();
|
|
||||||
const revisionInfo = fetcher.revisionInfo();
|
|
||||||
// Do nothing if the revision is already downloaded.
|
|
||||||
if (revisionInfo.local)
|
|
||||||
return revisionInfo;
|
|
||||||
await fetcher.download(revisionInfo.revision, onProgress);
|
|
||||||
logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`);
|
|
||||||
const localRevisions = await fetcher.localRevisions();
|
|
||||||
// Remove previous revisions.
|
// Remove previous revisions.
|
||||||
|
const playwright = require('.')[browser];
|
||||||
|
const fetcher = playwright._createBrowserFetcher();
|
||||||
const cleanupOldVersions = localRevisions.filter(revision => revision !== revisionInfo.revision).map(revision => fetcher.remove(revision));
|
const cleanupOldVersions = localRevisions.filter(revision => revision !== revisionInfo.revision).map(revision => fetcher.remove(revision));
|
||||||
await Promise.all([...cleanupOldVersions]);
|
await Promise.all([...cleanupOldVersions]);
|
||||||
|
|
||||||
return revisionInfo;
|
return revisionInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
function toMegabytes(bytes) {
|
|
||||||
const mb = bytes / 1024 / 1024;
|
|
||||||
return `${Math.round(mb * 10) / 10} Mb`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function logPolitely(toBeLogged) {
|
|
||||||
const logLevel = process.env.npm_config_loglevel;
|
|
||||||
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1;
|
|
||||||
|
|
||||||
if (!logLevelDisplay)
|
|
||||||
console.log(toBeLogged);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
module.exports = require('playwright-core').chromium;
|
module.exports = require('playwright-core').chromium;
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,17 @@
|
||||||
downloadBrowser('chromium', require('./index').chromium);
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
async function downloadBrowser(browser, playwright) {
|
*
|
||||||
let progressBar = null;
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
let lastDownloadedBytes = 0;
|
* you may not use this file except in compliance with the License.
|
||||||
function onProgress(downloadedBytes, totalBytes) {
|
* You may obtain a copy of the License at
|
||||||
if (!progressBar) {
|
*
|
||||||
const ProgressBar = require('progress');
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
|
*
|
||||||
complete: '=',
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
incomplete: ' ',
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
width: 20,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
total: totalBytes,
|
* See the License for the specific language governing permissions and
|
||||||
});
|
* limitations under the License.
|
||||||
}
|
*/
|
||||||
const delta = downloadedBytes - lastDownloadedBytes;
|
const {downloadBrowser} = require('playwright-core/download-browser');
|
||||||
lastDownloadedBytes = downloadedBytes;
|
downloadBrowser('chromium');
|
||||||
progressBar.tick(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetcher = playwright._createBrowserFetcher();
|
|
||||||
const revisionInfo = fetcher.revisionInfo();
|
|
||||||
await fetcher.download(revisionInfo.revision, onProgress);
|
|
||||||
logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toMegabytes(bytes) {
|
|
||||||
const mb = bytes / 1024 / 1024;
|
|
||||||
return `${Math.round(mb * 10) / 10} Mb`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function logPolitely(toBeLogged) {
|
|
||||||
const logLevel = process.env.npm_config_loglevel;
|
|
||||||
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1;
|
|
||||||
|
|
||||||
if (!logLevelDisplay)
|
|
||||||
console.log(toBeLogged);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "playwright-chromium",
|
"name": "playwright-chromium",
|
||||||
"version": "0.9.17-post",
|
"version": "0.9.17-post",
|
||||||
"description": "A high-level API to automate web browsers",
|
"description": "A high-level API to automate Chromium",
|
||||||
"repository": "github:Microsoft/playwright",
|
"repository": "github:Microsoft/playwright",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
|
|
@ -1 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
module.exports = require('playwright-core').firefox;
|
module.exports = require('playwright-core').firefox;
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,17 @@
|
||||||
downloadBrowser('firefox', require('./index').firefox);
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
async function downloadBrowser(browser, playwright) {
|
*
|
||||||
let progressBar = null;
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
let lastDownloadedBytes = 0;
|
* you may not use this file except in compliance with the License.
|
||||||
function onProgress(downloadedBytes, totalBytes) {
|
* You may obtain a copy of the License at
|
||||||
if (!progressBar) {
|
*
|
||||||
const ProgressBar = require('progress');
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
|
*
|
||||||
complete: '=',
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
incomplete: ' ',
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
width: 20,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
total: totalBytes,
|
* See the License for the specific language governing permissions and
|
||||||
});
|
* limitations under the License.
|
||||||
}
|
*/
|
||||||
const delta = downloadedBytes - lastDownloadedBytes;
|
const {downloadBrowser} = require('playwright-core/download-browser');
|
||||||
lastDownloadedBytes = downloadedBytes;
|
downloadBrowser('firefox');
|
||||||
progressBar.tick(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetcher = playwright._createBrowserFetcher();
|
|
||||||
const revisionInfo = fetcher.revisionInfo();
|
|
||||||
await fetcher.download(revisionInfo.revision, onProgress);
|
|
||||||
logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toMegabytes(bytes) {
|
|
||||||
const mb = bytes / 1024 / 1024;
|
|
||||||
return `${Math.round(mb * 10) / 10} Mb`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function logPolitely(toBeLogged) {
|
|
||||||
const logLevel = process.env.npm_config_loglevel;
|
|
||||||
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1;
|
|
||||||
|
|
||||||
if (!logLevelDisplay)
|
|
||||||
console.log(toBeLogged);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "playwright-firefox",
|
"name": "playwright-firefox",
|
||||||
"version": "0.9.17-post",
|
"version": "0.9.17-post",
|
||||||
"description": "A high-level API to automate web browsers",
|
"description": "A high-level API to automate Firefox",
|
||||||
"repository": "github:Microsoft/playwright",
|
"repository": "github:Microsoft/playwright",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
|
|
@ -1 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
module.exports = require('playwright-core').webkit;
|
module.exports = require('playwright-core').webkit;
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,17 @@
|
||||||
downloadBrowser('webkit', require('./index').webkit);
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
async function downloadBrowser(browser, playwright) {
|
*
|
||||||
let progressBar = null;
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
let lastDownloadedBytes = 0;
|
* you may not use this file except in compliance with the License.
|
||||||
function onProgress(downloadedBytes, totalBytes) {
|
* You may obtain a copy of the License at
|
||||||
if (!progressBar) {
|
*
|
||||||
const ProgressBar = require('progress');
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
progressBar = new ProgressBar(`Downloading ${browser} ${playwright._revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, {
|
*
|
||||||
complete: '=',
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
incomplete: ' ',
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
width: 20,
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
total: totalBytes,
|
* See the License for the specific language governing permissions and
|
||||||
});
|
* limitations under the License.
|
||||||
}
|
*/
|
||||||
const delta = downloadedBytes - lastDownloadedBytes;
|
const {downloadBrowser} = require('playwright-core/download-browser');
|
||||||
lastDownloadedBytes = downloadedBytes;
|
downloadBrowser('webkit');
|
||||||
progressBar.tick(delta);
|
|
||||||
}
|
|
||||||
|
|
||||||
const fetcher = playwright._createBrowserFetcher();
|
|
||||||
const revisionInfo = fetcher.revisionInfo();
|
|
||||||
await fetcher.download(revisionInfo.revision, onProgress);
|
|
||||||
logPolitely(`${browser} downloaded to ${revisionInfo.folderPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
function toMegabytes(bytes) {
|
|
||||||
const mb = bytes / 1024 / 1024;
|
|
||||||
return `${Math.round(mb * 10) / 10} Mb`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function logPolitely(toBeLogged) {
|
|
||||||
const logLevel = process.env.npm_config_loglevel;
|
|
||||||
const logLevelDisplay = ['silent', 'error', 'warn'].indexOf(logLevel) > -1;
|
|
||||||
|
|
||||||
if (!logLevelDisplay)
|
|
||||||
console.log(toBeLogged);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "playwright-webkit",
|
"name": "playwright-webkit",
|
||||||
"version": "0.9.17-post",
|
"version": "0.9.17-post",
|
||||||
"description": "A high-level API to automate web browsers",
|
"description": "A high-level API to automate WebKit",
|
||||||
"repository": "github:Microsoft/playwright",
|
"repository": "github:Microsoft/playwright",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,17 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) Microsoft Corporation.
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
console.error('This package, "playwright", is a placeholder. Please install "playwright-chromium", "playwright-firefox", or "playwright-webkit" to use playwright.');
|
console.error('This package, "playwright", is a placeholder. Please install "playwright-chromium", "playwright-firefox", or "playwright-webkit" to use playwright.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
Loading…
Reference in a new issue