Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal becomes unusable after exiting from "web-ext run" in Node.js 10.2.x and 10.3.0 #1331

Open
Rob--W opened this issue Jun 5, 2018 · 7 comments
Assignees

Comments

@Rob--W
Copy link
Member

Rob--W commented Jun 5, 2018

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: nodejs/node#21020

Any of the following work-arounds can be used:

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.

@Rob--W Rob--W self-assigned this Jun 5, 2018
@danhumphrey
Copy link

danhumphrey commented Jul 31, 2018

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

@Rob--W
Copy link
Member Author

Rob--W commented Jul 31, 2018

@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?

@danhumphrey
Copy link

@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!

@Rob--W
Copy link
Member Author

Rob--W commented Aug 1, 2018

@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)

@rpl
Copy link
Member

rpl commented Aug 1, 2018

@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):

const allowInput = !noInput;
if (!allowInput) {
log.debug('Input has been disabled because of noInput==true');
}
const watcher: Watchpack = createWatcher({
reloadExtension: (watchedSourceDir) => {
extensionRunner.reloadExtensionBySourceDir(watchedSourceDir);
},
sourceDir,
artifactsDir,
ignoreFiles,
});
extensionRunner.registerCleanup(() => {
watcher.close();
if (allowInput) {
stdin.pause();
}
});
if (allowInput && stdin instanceof tty.ReadStream && stdin.isTTY) {
readline.emitKeypressEvents(stdin);
stdin.setRawMode(true);

@danhumphrey
Copy link

danhumphrey commented Aug 1, 2018

@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! page-modeller@0.0.1 start:firefox: `gulp startFirefox --dev`
npm ERR! Exit status 130
npm ERR!
npm ERR! Failed at the page-modeller@0.0.1 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:

@RussCoder
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants