How to use opn - 10 common examples

To help you get started, we’ve selected a few opn examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zhongzhi107 / universal-react-starter-kit / tools / open-browser / index.js View on Github external
if (process.platform === 'darwin') {
    try {
      // Try our best to reuse existing tab
      // on OS X Google Chrome with AppleScript
      execSync('ps cax | grep "Google Chrome"');
      execSync(
        `osascript ${path.join(__dirname, './open-chrome.applescript')} ${url}`,
      );
      return true;
    } catch (err) {
      // Ignore errors.
    }
  }
  // Fallback to opn
  try {
    opn(url);
    return true;
  } catch (err) {
    return false;
  }
};
github evilz / vscode-reveal / test / browserHelper.jest.ts View on Github external
test('Should use headless chrome only when needed', async () => {
    (fs.statSync as any).mockImplementation((_) => true);
    (os.platform as any).mockImplementation(() => 'win32');
    (opn as any).mockImplementation(async (url, opts) => { })
    await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl")

    expect(opn.mock.calls.length).toBe(1);
    expect(opn.mock.calls[0][0]).toBe("http://theurl")
    expect(opn.mock.calls[0][1]).toStrictEqual({ app: DEFAULT_CHROME_PATH.WINx86 })

    await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl", true)

    expect(opn.mock.calls.length).toBe(2);
    expect(opn.mock.calls[1][0]).toBe("http://theurl")
    expect(opn.mock.calls[1][1]).toStrictEqual({ app: [DEFAULT_CHROME_PATH.WINx86, "--headless"] })
})
github evilz / vscode-reveal / test / browserHelper.jest.ts View on Github external
test('Should use headless chrome only when needed', async () => {
    (fs.statSync as any).mockImplementation((_) => true);
    (os.platform as any).mockImplementation(() => 'win32');
    (opn as any).mockImplementation(async (url, opts) => { })
    await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl")

    expect(opn.mock.calls.length).toBe(1);
    expect(opn.mock.calls[0][0]).toBe("http://theurl")
    expect(opn.mock.calls[0][1]).toStrictEqual({ app: DEFAULT_CHROME_PATH.WINx86 })

    await openInBrowser(DEFAULT_CHROME_PATH.WINx86, "http://theurl", true)

    expect(opn.mock.calls.length).toBe(2);
    expect(opn.mock.calls[1][0]).toBe("http://theurl")
    expect(opn.mock.calls[1][1]).toStrictEqual({ app: [DEFAULT_CHROME_PATH.WINx86, "--headless"] })
})
github satya164 / quik / src / quik-cli.js View on Github external
process.exit(1);
    });
} else {
  server({
    root: process.cwd(),
    port: argv.port,
    run: argv.run,
    watch: argv.watch,
  }).listen(argv.port);

  const url = `http://localhost:${argv.port}`;

  console.log(`Quik is serving files at ${chalk.blue(url)}`);

  if (argv.browser) {
    opn(url, { app: argv.browser });
  } else {
    opn(url);
  }
}
github patternplate / patternplate / source / binary / patternplate.js View on Github external
const [, consoleCommand] = input;
		await application.server.run(consoleCommand, settings);
		return {mode: 'console'};
	}

	await application.start();

	if (settings.open) {
		const {host, port} = application.configuration.server;
		const address = `http://${host}:${port}`;
		const explicit = typeof settings.open === 'string';
		const openOptions = explicit ? {app: settings.open} : {};
		const browserName = explicit ? settings.open : 'default browser';
		application.log.info(`Opening ${browserName} at ${address}`);

		opn(address, openOptions)
			.catch(error => {
				application.log.error(error);
				console.log(error.stack);
			});
	}

	return {mode: 'server'};
}
github Sitecore / jss / samples / sitecore-embedded-jss-app / build / start.js View on Github external
server.listen(options.port, options.host, (err) => {
      if (err) {
        reject(err);
        return;
      }

      console.log(`Starting webpack dev server at ${options.uri()}`);
      open(options.uri());
      resolve();
    });
  });
github Sitecore / jss / packages / sitecore-jss-rendering-host / src / devServer.ts View on Github external
(stats) => {
        if (!browserOpened) {
          console.log('opening browser', stats.compilation.compiler.name);
          openBrowser(urlToOpenOnStart).then(() => {
            browserOpened = true;
          });
        }
      }
    );
github coryhouse / fluent2017 / buildScripts / srcServer.js View on Github external
app.listen(port, function(err) {
  if (err) {
    console.log(err);
  } else {
    opn('http://localhost:' + port);
  }
});
github yinxin630 / fiora / build / dev-server.ts View on Github external
app.listen(port, (err) => {
    if (err) {
        console.log(err);
        return;
    }

    if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') {
        opn(uri);
    }
});
github VladimirIvanin / insales-uploader / lib / tools / browser.js View on Github external
export function startBrowser (url, options) {
  if (options && options.start || options.launch) {
    const _option = _.omit(options, ['start', 'launch']);
    opn(url, options)
  }
}

opn

Open stuff like URLs, files, executables. Cross-platform.

MIT
Latest version published 6 years ago

Package Health Score

66 / 100
Full package analysis

Popular opn functions