web-ext
                                
                                 web-ext copied to clipboard
                                
                                    web-ext copied to clipboard
                            
                            
                            
                        Terminal becomes unusable after exiting from "web-ext run" in Node.js 10.2.x and 10.3.0
When I type in the terminal after exiting from web-ext run, the input is not displayed. When I press enter, the typed command is executed. This is a bug that only happens in Node.js 10.2.x and 10.3.0.
This is apparently a bug in Node.js: https://github.com/nodejs/node/issues/21020
Any of the following work-arounds can be used:
- Type stty saneand press Enter.
- Downgrade to Node.js 10.1.0 or earlier.
- Wait until the patch for https://github.com/nodejs/node/issues/21020 is released (the current version is 10.3.0 according to https://nodejs.org/en/download/releases , so I guess that the next version is 10.3.1).
There is nothing that we can do, short of not using process.stdin.setRawMode(true);. Let's keep this issue open until the latest version of Node.js has been fixed. Then users of web-ext can find this issue + work-around on the issue tracker.
I'm currently using v8.10.0 and I experience the same problem.
The extension will reload if any source file changes
Press R to reload (and Ctrl-C to quit)
After pressing Ctrl-C is see this:
Exiting web-ext on user request
... but now have an unusable terminal as you've described.
$ node --version
v8.10.0
@danhumphrey I can't reproduce the issue with Node.js 8.10.0, web-ext 2.7.0 nor master on ArchLinux. What operating system are you using, which web-ext version are you using?
@Rob--W Thanks for your quick reply.
Mac OS 10.13. I've also just tried Windows 10.
Originally tried node v8.10.0 and just tried switching to v6.10.3 and the same problem exists.
Maybe it's got something to do with how I'm using it.. let me elaborate:
I have a gulp task to build and launch an extension, the final function is shown below:
function launchFirefox(cb) {
    webext.cmd
      .run(
        {
          sourceDir: distPath,
          startUrl: pkg.homepage
        },
        {
          shouldExitProgram: false
        }
      )
      .catch(onError);
    logUpdate(
      `Firefox should now be open with the ${pkg.name} extension loaded.`
    );
    cb();
  }
The gulp task completes successfully - here's the final few lines of the log output:
[08:58:43] Finished 'javascript' after 3.12 s
[08:58:43] Starting 'launchFirefox'...
Running web extension from C:\path\to\ext\dist
[08:58:43] Firefox should now be open with the ext-name extension loaded.
[08:58:43] Finished 'launchFirefox' after 399 ms
[08:58:43] Finished 'startFirefox' after 4.81 s
Use --verbose or open Tools > Web Developer > Browser Console to see logging
Installed C:\path\to\ext\dist as a temporary add-on
The extension will reload if any source file changes
Press R to reload (and Ctrl-C to quit)
Am I doing something wrong with how I'm using web-ext? Thanks!
@danhumphrey I tried to reproduce your issue but can't. Can you share a minimal project that shows the issue? This is my attempt to reproduce:
$ ls
background.js  contentscript.js  gulpfile.js  manifest.json  runwebext.js
$ cat runwebext.js 
webext = require('web-ext').default;
distPath = __dirname;
pkg = {homepage: 'http://example.com'};
onError = console.error;
    webext.cmd
      .run(
        {
          sourceDir: distPath,
          startUrl: pkg.homepage
        },
        {
          shouldExitProgram: false
        }
      )
      .catch(onError);
$ cat gulpfile.js 
gulp = require('gulp');
gulp.task('default', function(cb) {
    console.log('before run');
    require('./runwebext');
    console.log('after run');
    cb();
});
$ gulp
[11:56:53] Using gulpfile /tmp/werepro/gulpfile.js
[11:56:53] Starting 'default'...
before run
Running web extension from /tmp/werepro
after run
[11:56:53] Finished 'default' after 195 ms
Use --verbose or open Tools > Web Developer > Browser Console to see logging
Installed /tmp/werepro as a temporary add-on
The extension will reload if any source file changes
Press R to reload (and Ctrl-C to quit)
$ node runwebext.js 
Running web extension from /tmp/werepro
Use --verbose or open Tools > Web Developer > Browser Console to see logging
Installed /tmp/werepro as a temporary add-on
The extension will reload if any source file changes
Press R to reload (and Ctrl-C to quit)
@danhumphrey when running a web-ext command by requiring it as a nodejs module, it may be useful to include the noInput option explicitly set to true, e.g.
   webext.cmd.run({
     noInput: true,
     sourceDir: distPath,
     startUrl: pkg.homepage,
   }, {
     shouldExitProgram: false
   }).then(() => {...}).catch(...);
This options (when set to true) prevents web-ext from setting the raw mode on the stdin (needed by web-ext to be able to intercept the keys typed on the console stdin, which is also very likely what is making the terminal unusable on exit):
https://github.com/mozilla/web-ext/blob/f9db35b30a7477cadd3f9101e1ee593efb2fe875/src/extension-runners/index.js#L286-L309
@Rob--W
Sure, I'll do that shortly if required.... I just want to follow up on the noInput option first..
@rpl Yes, that helps - I can now Ctrl-C and regain control of the terminal, but can I do so gracefully and avoid:
^Cnpm ERR! code ELIFECYCLE
npm ERR! errno 130
npm ERR! [email protected] start:firefox: `gulp startFirefox --dev`
npm ERR! Exit status 130
npm ERR!
npm ERR! Failed at the [email protected] start:firefox script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
I got the same issue, I use
- Node.js 12.16.1
- web-ext 4.2.0
- Firefox 75.0
- Windows 10
In a usual cmd.exe web-ext run exists only when the browser is closed, when I press Ctrl+C it doesn't close the browser and exit, but waits.
In an unstandard terminal ConEMU, which I use, it hangs up regardless further actions, even when the browser is closed it doesn't exit.
So, perhaps, the main reason in the unstandard terminal.