每次在终端运行open http://localhost:8080都会打开一个新的选项卡。
当可用时,创建-反应-应用程序如何重用现有的浏览器选项卡?
更新
看起来,这里就是魔法发生的地方:
function startBrowserProcess(browser, url) {
// If we're on OS X, the user hasn't specifically
// requested a different browser, we can try opening
// Chrome with AppleScript. This lets us reuse an
// existing tab when possible instead of creating a new one.
const shouldTryOpenChromeWithAppleScript =
process.platform === 'darwin' &&
(typeof browser !== 'string' || browser === OSX_CHROME);
if (shouldTryOpenChromeWithAppleScript) {
try {
// Try our best to reuse existing tab
// on OS X Google Chrome with AppleScript
execSync('ps cax | grep "Google Chrome"');
execSync('osascript openChrome.applescript "' + encodeURI(url) + '"', {
cwd: __dirname,
stdio: 'ignore',
});
return true;
} catch (err) {
// Ignore errors.
}
}
// Another special case: on OS X, check if BROWSER has been set to "open".
// In this case, instead of passing `open` to `opn` (which won't work),
// just ignore it (thus ensuring the intended behavior, i.e. opening the system browser):
// https://github.com/facebook/create-react-app/pull/1690#issuecomment-283518768
if (process.platform === 'darwin' && browser === 'open') {
browser = undefined;
}
// Fallback to opn
// (It will always open new tab)
try {
var options = { app: browser };
opn(url, options).catch(() => {}); // Prevent `unhandledRejection` error.
return true;
} catch (err) {
return false;
}
}不过,我还是不知道这是怎么回事。我在OS上,而且我有osascript二进制文件,令人惊讶的是。但我不知道如何在终点站内使用它。
我尝试过osascript openChrome.applescript "localhost:8080",但是我得到了以下错误:
osascript: openChrome.applescript: No such file or directory
如果存在osascript命令,那么在当前选项卡中打开http://localhost:8080的正确用法是什么?
更新
它看起来像openChrome.applescript文件是否包含在创建-反应-应用程序中?,但我不知道在哪里。
发布于 2018-02-21 21:41:25
我刚刚测试了osascript /path/to/openChrome.applescript "http://localhost:8080",它就像预期的那样工作。
如果您没有openChrome.applescript脚本,那么这里是它的源代码URL:openChrome.applescript
https://stackoverflow.com/questions/48913566
复制相似问题