File tree Expand file tree Collapse file tree 6 files changed +40
-4
lines changed Expand file tree Collapse file tree 6 files changed +40
-4
lines changed Original file line number Diff line number Diff line change @@ -3478,6 +3478,7 @@ const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
3478
3478
<!-- GEN:toc -->
3479
3479
- [ browserType.connect(options)] ( #browsertypeconnectoptions )
3480
3480
- [ browserType.devices] ( #browsertypedevices )
3481
+ - [ browserType.downloadBrowserIfNeeded([ progress] )] ( #browsertypedownloadbrowserifneededprogress )
3481
3482
- [ browserType.errors] ( #browsertypeerrors )
3482
3483
- [ browserType.executablePath()] ( #browsertypeexecutablepath )
3483
3484
- [ browserType.launch([ options] )] ( #browsertypelaunchoptions )
@@ -3516,6 +3517,12 @@ const iPhone = webkit.devices['iPhone 6'];
3516
3517
})();
3517
3518
```
3518
3519
3520
+ #### browserType.downloadBrowserIfNeeded([ progress] )
3521
+ - ` progress ` <[ function] > If download is initiated, this function is called with two parameters: ` downloadedBytes ` and ` totalBytes ` .
3522
+ - returns: <[ Promise] > promise that resolves when browser is successfully downloaded.
3523
+
3524
+ Download browser binary if it is missing.
3525
+
3519
3526
#### browserType.errors
3520
3527
- returns: <[ Object] >
3521
3528
- ` TimeoutError ` <[ function] > A class of [ TimeoutError] .
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ async function downloadBrowser(browser) {
38
38
// Do nothing if the revision is already downloaded.
39
39
if ( revisionInfo . local )
40
40
return revisionInfo ;
41
- await fetcher . download ( revisionInfo . revision , onProgress ) ;
41
+ await browserType . downloadBrowserIfNeeded ( onProgress ) ;
42
42
logPolitely ( `${ browser } downloaded to ${ revisionInfo . folderPath } ` ) ;
43
43
return revisionInfo ;
44
44
}
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import { TimeoutError } from '../errors';
19
19
import { Browser , ConnectOptions } from '../browser' ;
20
20
import { BrowserContext } from '../browserContext' ;
21
21
import { BrowserServer } from './browserServer' ;
22
+ import { OnProgressCallback } from './browserFetcher' ;
22
23
23
24
export type BrowserArgOptions = {
24
25
headless ?: boolean ,
@@ -44,6 +45,7 @@ export interface BrowserType {
44
45
launchServer ( options ?: LaunchOptions & { port ?: number } ) : Promise < BrowserServer > ;
45
46
launchPersistent ( userDataDir : string , options ?: LaunchOptions ) : Promise < BrowserContext > ;
46
47
connect ( options : ConnectOptions ) : Promise < Browser > ;
48
+ downloadBrowserIfNeeded ( progress ?: OnProgressCallback ) : Promise < void > ;
47
49
devices : types . Devices ;
48
50
errors : { TimeoutError : typeof TimeoutError } ;
49
51
}
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ import * as fs from 'fs';
19
19
import * as os from 'os' ;
20
20
import * as path from 'path' ;
21
21
import * as util from 'util' ;
22
- import { BrowserFetcher , BrowserFetcherOptions } from '../server/browserFetcher' ;
22
+ import { BrowserFetcher , OnProgressCallback , BrowserFetcherOptions } from '../server/browserFetcher' ;
23
23
import { DeviceDescriptors } from '../deviceDescriptors' ;
24
24
import * as types from '../types' ;
25
25
import { assert } from '../helper' ;
@@ -194,6 +194,15 @@ export class Chromium implements BrowserType {
194
194
return chromeArguments ;
195
195
}
196
196
197
+ async downloadBrowserIfNeeded ( onProgress ?: OnProgressCallback ) {
198
+ const fetcher = this . _createBrowserFetcher ( ) ;
199
+ const revisionInfo = fetcher . revisionInfo ( ) ;
200
+ // Do nothing if the revision is already downloaded.
201
+ if ( revisionInfo . local )
202
+ return ;
203
+ await fetcher . download ( revisionInfo . revision , onProgress ) ;
204
+ }
205
+
197
206
_createBrowserFetcher ( options : BrowserFetcherOptions = { } ) : BrowserFetcher {
198
207
const downloadURLs = {
199
208
linux : '%s/chromium-browser-snapshots/Linux_x64/%d/%s.zip' ,
Original file line number Diff line number Diff line change 16
16
*/
17
17
18
18
import { FFBrowser } from '../firefox/ffBrowser' ;
19
- import { BrowserFetcher , BrowserFetcherOptions } from './browserFetcher' ;
19
+ import { BrowserFetcher , OnProgressCallback , BrowserFetcherOptions } from './browserFetcher' ;
20
20
import { DeviceDescriptors } from '../deviceDescriptors' ;
21
21
import { launchProcess , waitForLine } from './processLauncher' ;
22
22
import * as types from '../types' ;
@@ -44,6 +44,15 @@ export class Firefox implements BrowserType {
44
44
this . _revision = preferredRevision ;
45
45
}
46
46
47
+ async downloadBrowserIfNeeded ( onProgress ?: OnProgressCallback ) {
48
+ const fetcher = this . _createBrowserFetcher ( ) ;
49
+ const revisionInfo = fetcher . revisionInfo ( ) ;
50
+ // Do nothing if the revision is already downloaded.
51
+ if ( revisionInfo . local )
52
+ return ;
53
+ await fetcher . download ( revisionInfo . revision , onProgress ) ;
54
+ }
55
+
47
56
name ( ) {
48
57
return 'firefox' ;
49
58
}
Original file line number Diff line number Diff line change 15
15
* limitations under the License.
16
16
*/
17
17
18
- import { BrowserFetcher , BrowserFetcherOptions } from './browserFetcher' ;
18
+ import { BrowserFetcher , OnProgressCallback , BrowserFetcherOptions } from './browserFetcher' ;
19
19
import { DeviceDescriptors } from '../deviceDescriptors' ;
20
20
import { TimeoutError } from '../errors' ;
21
21
import * as types from '../types' ;
@@ -52,6 +52,15 @@ export class WebKit implements BrowserType {
52
52
return 'webkit' ;
53
53
}
54
54
55
+ async downloadBrowserIfNeeded ( onProgress ?: OnProgressCallback ) {
56
+ const fetcher = this . _createBrowserFetcher ( ) ;
57
+ const revisionInfo = fetcher . revisionInfo ( ) ;
58
+ // Do nothing if the revision is already downloaded.
59
+ if ( revisionInfo . local )
60
+ return ;
61
+ await fetcher . download ( revisionInfo . revision , onProgress ) ;
62
+ }
63
+
55
64
async launch ( options ?: LaunchOptions & { slowMo ?: number } ) : Promise < WKBrowser > {
56
65
const { browserServer, transport } = await this . _launchServer ( options , 'local' ) ;
57
66
const browser = await WKBrowser . connect ( transport ! , options && options . slowMo ) ;
You can’t perform that action at this time.
0 commit comments