Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(firefox): do not run firefox as a part of the installation process (#2125)

Pavel Feldman793a2bf7d489
diff --git a/src/install/installer.ts b/src/install/installer.ts
index 7806c2e6fa..67ee570289 100644
--- a/src/install/installer.ts
+++ b/src/install/installer.ts
@@ -22,7 +22,6 @@ import * as util from 'util';
import * as removeFolder from 'rimraf';
import * as browserPaths from '../install/browserPaths';
import * as browserFetcher from '../install/browserFetcher';
-import { Playwright } from '../server/playwright';
const fsMkdirAsync = util.promisify(fs.mkdir.bind(fs));
const fsReaddirAsync = util.promisify(fs.readdir.bind(fs));
@@ -74,24 +73,10 @@ async function validateCache(packagePath: string, browsersPath: string, linksDir
const myBrowsers = JSON.parse((await fsReadFileAsync(path.join(packagePath, 'browsers.json'))).toString())['browsers'];
for (const browser of myBrowsers) {
const browserPath = browserPaths.browserDirectory(browsersPath, browser);
- if (await browserFetcher.downloadBrowserWithProgressBar(browserPath, browser))
- await installBrowser(packagePath, browserPath, browser);
+ await browserFetcher.downloadBrowserWithProgressBar(browserPath, browser);
}
}
-async function installBrowser(packagePath: string, browserPath: string, browser: browserPaths.BrowserDescriptor) {
- if (browser.name !== 'firefox')
- return;
- const firefox = new Playwright(packagePath, [browser]).firefox!;
- const userDataDir = path.join(browserPath, 'cached-profile');
- await fsMkdirAsync(userDataDir, { recursive: true });
- logPolitely('Pre-compiling Firefox scripts at ' + userDataDir);
- const browserContext = await firefox.launchPersistentContext(userDataDir);
- const page = await browserContext.newPage();
- await page.goto('data:text/html,<html>Hello world</html>');
- await browserContext.close();
-}
-
function sha1(data: string): string {
const sum = crypto.createHash('sha1');
sum.update(data);
diff --git a/src/server/browserType.ts b/src/server/browserType.ts
index de9c794708..5f897b5e7c 100644
--- a/src/server/browserType.ts
+++ b/src/server/browserType.ts
@@ -54,14 +54,13 @@ export interface BrowserType<Browser> {
export abstract class AbstractBrowserType<Browser> implements BrowserType<Browser> {
private _name: string;
- readonly _browserPath: string;
private _executablePath: string | undefined;
constructor(packagePath: string, browser: browserPaths.BrowserDescriptor) {
this._name = browser.name;
const browsersPath = browserPaths.browsersPath(packagePath);
- this._browserPath = browserPaths.browserDirectory(browsersPath, browser);
- this._executablePath = browserPaths.executablePath(this._browserPath, browser);
+ const browserPath = browserPaths.browserDirectory(browsersPath, browser);
+ this._executablePath = browserPaths.executablePath(browserPath, browser);
}
executablePath(): string {
diff --git a/src/server/firefox.ts b/src/server/firefox.ts
index d1d430ee97..81d8021f67 100644
--- a/src/server/firefox.ts
+++ b/src/server/firefox.ts
@@ -91,7 +91,7 @@ export class Firefox extends AbstractBrowserType<FFBrowser> {
let temporaryProfileDir = null;
if (!userDataDir) {
- userDataDir = await this._createTemporaryProfile();
+ userDataDir = await mkdtempAsync(path.join(os.tmpdir(), 'playwright_dev_firefox_profile-'));
temporaryProfileDir = userDataDir;
}
@@ -189,15 +189,6 @@ export class Firefox extends AbstractBrowserType<FFBrowser> {
return firefoxArguments;
}
-
- async _createTemporaryProfile(): Promise<string> {
- const userDataDir = await mkdtempAsync(path.join(os.tmpdir(), 'playwright_dev_firefox_profile-'));
- const cachedProfileDir = path.join(this._browserPath, 'cached-profile');
- const files = fs.readdirSync(cachedProfileDir);
- for (const file of files)
- copyRecursiveSync(path.join(cachedProfileDir, file), userDataDir);
- return userDataDir;
- }
}
function wrapTransportWithWebSocket(transport: ConnectionTransport, logger: InnerLogger, port: number): WebSocketWrapper {
@@ -328,18 +319,3 @@ function wrapTransportWithWebSocket(transport: ConnectionTransport, logger: Inne
return new WebSocketWrapper(wsEndpoint,
[pendingBrowserContextCreations, pendingBrowserContextDeletions, browserContextIds, sessionToSocket, sockets]);
}
-
-function copyRecursiveSync(source: string, targetFolder: string) {
- const target = path.join(targetFolder, path.basename(source));
- const stat = fs.lstatSync(source);
- if (stat.isFile()) {
- fs.copyFileSync(source, target);
- return;
- }
- if (stat.isDirectory()) {
- fs.mkdirSync(target, { recursive: true });
- const files = fs.readdirSync(source);
- for (const file of files)
- copyRecursiveSync(path.join(source, file), target);
- }
-}