@@ -4,6 +4,7 @@ import IPuppetLauncher from '@secret-agent/puppet-interfaces/IPuppetLauncher';
44import * as os from 'os' ;
55import * as Path from 'path' ;
66import IBrowserEngine from '@secret-agent/core-interfaces/IBrowserEngine' ;
7+ import { IPuppetLaunchError } from '@secret-agent/puppet-interfaces/IPuppetLaunchError' ;
78import { Browser } from './lib/Browser' ;
89import { Connection } from './lib/Connection' ;
910
@@ -51,29 +52,35 @@ const PuppetLauncher: IPuppetLauncher = {
5152 const connection = new Connection ( transport ) ;
5253 return await Browser . create ( connection , engine , close ) ;
5354 } catch ( error ) {
54- close ( ) ;
55+ await close ( ) ;
5556 throw error ;
5657 }
5758 } ,
58- translateLaunchError ( error : Error ) : Error {
59+ translateLaunchError ( rawError : Error ) : IPuppetLaunchError {
5960 // These error messages are taken from Chromium source code as of July, 2020:
6061 // https://github.com/chromium/chromium/blob/70565f67e79f79e17663ad1337dc6e63ee207ce9/content/browser/zygote_host/zygote_host_impl_linux.cc
62+ const error = {
63+ message : rawError . message ,
64+ stack : rawError . stack ,
65+ name : 'PuppetLaunchError' ,
66+ isSandboxError : false ,
67+ } ;
6168 if (
62- ! error . message . includes ( 'crbug.com/357670' ) &&
63- ! error . message . includes ( 'No usable sandbox!' ) &&
64- ! error . message . includes ( 'crbug.com/638180' )
69+ error . message . includes ( 'crbug.com/357670' ) ||
70+ error . message . includes ( 'No usable sandbox!' ) ||
71+ error . message . includes ( 'crbug.com/638180' )
6572 ) {
66- return error ;
73+ error . stack += [
74+ `\nChromium sandboxing failed!` ,
75+ `================================` ,
76+ `To workaround sandboxing issues, do either of the following:` ,
77+ ` - (preferred): Configure environment to support sandboxing (as here: https://github.com/ulixee/secret-agent/tree/master/tools/docker)` ,
78+ ` - (alternative): Launch Chromium without sandbox using 'NO_CHROME_SANDBOX=false' environmental variable` ,
79+ `================================` ,
80+ `` ,
81+ ] . join ( '\n' ) ;
82+ error . isSandboxError = true ;
6783 }
68- error . stack += [
69- `\nChromium sandboxing failed!` ,
70- `================================` ,
71- `To workaround sandboxing issues, do either of the following:` ,
72- ` - (preferred): Configure environment to support sandboxing (eg: in Docker, use custom seccomp profile + non-root user + --ipc=host)` ,
73- ` - (alternative): Launch Chromium without sandbox using 'NO_CHROME_SANDBOX=false' environmental variable` ,
74- `================================` ,
75- `` ,
76- ] . join ( '\n' ) ;
7784 return error ;
7885 } ,
7986} ;
0 commit comments