Can I make Node.js opn open the browser with maximized window when Node.js itself is started in a minimized console window ( Windows 10 )?

可紊 提交于 2019-12-25 18:25:30

问题


My problem is that it seems that on Windows 10 a desktop link (.lnk) that opens a console application in a minimized window makes all windows opened by this console application to be also minimized.

I would like to start Node.js in a minimized console window, but at the same time make Node.js opn open the browser in a maximized window ( this makes sense, since I'm not interested in the console output, rather I want the output in the browser window ).

opn("http://localhost:9000") // but hey, in maximized window!

Is there any way I can achieve this either by Node.js or by some Windows manipulation?


回答1:


I made it. It is a Windows trick.

Based on this answer:

How do I minimize the command prompt from my bat file

if not DEFINED IS_MINIMIZED set IS_MINIMIZED=1 && start "" /min "%~dpnx0" %* && exit
... script logic here ...
exit

This a trick for a script to run itself in a minimized window. But somehow the property inherited from the .lnk remains maximized, so the browser window opened by the script running in its self minimized window opens the browser maximized.




回答2:


There is a workaround, at least in my used case. But this just minimized the node console only. It will still appear in the taskbar.

I just created a shortcut with

  • Target: C:\WINDOWS\system32\cmd.exe /c start /min node < Your Application >
  • Start in: < Path to your application >

"Start in" is not required if you specify the full path to your application

Examples:

  • Target: C:\WINDOWS\system32\cmd.exe /c start /min node "C:\Users\jjyong\Documents\Programming\Node\PriceTracking\app.js"

    Or

  • Target: C:\WINDOWS\system32\cmd.exe /c start /min node app.js

  • Start in: C:\Users\jjyong\Documents\Programming\Node\PriceTracking

Note: I have only tested using NodeJS version 12.13.1 with PuppeteerJS running chromium with "headless: false"



来源:https://stackoverflow.com/questions/48175160/can-i-make-node-js-opn-open-the-browser-with-maximized-window-when-node-js-itsel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!