download-browser.js
This commit is contained in:
parent
b3ea94a4d7
commit
1d884c5a52
|
|
@ -10,8 +10,11 @@ lib/injected/
|
|||
!lib/**/*.d.ts
|
||||
!index.d.ts
|
||||
|
||||
# root for "playwright" package
|
||||
# used for npm install scripts
|
||||
!download-browser.js
|
||||
|
||||
# root for "playwright-core" package
|
||||
!index.js
|
||||
|
||||
# root for "playwright/web"
|
||||
# root for "playwright-core/web"
|
||||
!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
|
||||
|
||||
try {
|
||||
console.log('Building playwright...');
|
||||
require('child_process').execSync('npm run build', {
|
||||
stdio: 'ignore'
|
||||
});
|
||||
} catch (e) {
|
||||
}
|
||||
const {downloadBrowser} = require('./download-browser');
|
||||
|
||||
(async function() {
|
||||
const protocolGenerator = require('./utils/protocol-types-generator');
|
||||
try {
|
||||
const chromeRevision = await downloadBrowser('chromium', require('./index').chromium);
|
||||
const chromeRevision = await downloadAndCleanup('chromium');
|
||||
await protocolGenerator.generateChromiunProtocol(chromeRevision);
|
||||
} catch (e) {
|
||||
console.warn(e.message);
|
||||
}
|
||||
|
||||
try {
|
||||
const firefoxRevision = await downloadBrowser('firefox', require('./index').firefox);
|
||||
const firefoxRevision = await downloadAndCleanup('firefox');
|
||||
await protocolGenerator.generateFirefoxProtocol(firefoxRevision);
|
||||
} catch (e) {
|
||||
console.warn(e.message);
|
||||
}
|
||||
|
||||
try {
|
||||
const webkitRevision = await downloadBrowser('webkit', require('./index').webkit);
|
||||
const webkitRevision = await downloadAndCleanup('webkit');
|
||||
await protocolGenerator.generateWebKitProtocol(webkitRevision);
|
||||
} catch (e) {
|
||||
console.warn(e.message);
|
||||
}
|
||||
})();
|
||||
|
||||
async function downloadBrowser(browser, playwright) {
|
||||
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);
|
||||
}
|
||||
async function downloadAndCleanup(browser) {
|
||||
const revisionInfo = await downloadBrowser(browser);
|
||||
|
||||
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.
|
||||
const playwright = require('.')[browser];
|
||||
const fetcher = playwright._createBrowserFetcher();
|
||||
const cleanupOldVersions = localRevisions.filter(revision => revision !== revisionInfo.revision).map(revision => fetcher.remove(revision));
|
||||
await Promise.all([...cleanupOldVersions]);
|
||||
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,39 +1,17 @@
|
|||
downloadBrowser('chromium', require('./index').chromium);
|
||||
|
||||
async function downloadBrowser(browser, playwright) {
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const {downloadBrowser} = require('playwright-core/download-browser');
|
||||
downloadBrowser('chromium');
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "playwright-chromium",
|
||||
"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",
|
||||
"main": "index.js",
|
||||
"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;
|
||||
|
|
|
|||
|
|
@ -1,39 +1,17 @@
|
|||
downloadBrowser('firefox', require('./index').firefox);
|
||||
|
||||
async function downloadBrowser(browser, playwright) {
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const {downloadBrowser} = require('playwright-core/download-browser');
|
||||
downloadBrowser('firefox');
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "playwright-firefox",
|
||||
"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",
|
||||
"main": "index.js",
|
||||
"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;
|
||||
|
|
|
|||
|
|
@ -1,39 +1,17 @@
|
|||
downloadBrowser('webkit', require('./index').webkit);
|
||||
|
||||
async function downloadBrowser(browser, playwright) {
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const {downloadBrowser} = require('playwright-core/download-browser');
|
||||
downloadBrowser('webkit');
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "playwright-webkit",
|
||||
"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",
|
||||
"main": "index.js",
|
||||
"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.');
|
||||
process.exit(1);
|
||||
Loading…
Reference in a new issue