File tree Expand file tree Collapse file tree
testing/testing-screenshot Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -40,7 +40,17 @@ export class Worker {
4040 return this . browser ;
4141 }
4242
43+ async relaunch ( ) {
44+ await this . close ( ) ;
45+ return this . launch ( ) ;
46+ }
47+
4348 async screenshot ( { htmlcss, viewport } : ScreenshotOptions ) {
49+ // check if page is available (try to avoid TargetClosedError)
50+ if ( ! this . page || this . page . isClosed ( ) ) {
51+ await this . relaunch ( ) ;
52+ }
53+
4454 this . page . setViewport ( viewport ) ;
4555 await this . page . setContent ( htmlcss , { waitUntil : "networkidle0" } ) ;
4656 const buffer = await this . page . screenshot ( {
@@ -52,7 +62,11 @@ export class Worker {
5262 }
5363
5464 async close ( ) {
55- await this . browser . close ( ) ;
65+ try {
66+ await this . browser . close ( ) ;
67+ } catch ( e ) { }
68+ this . browser = null ;
69+ this . page = null ;
5670 }
5771
5872 terminate ( ) {
You can’t perform that action at this time.
0 commit comments