diff options
| author | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
|---|---|---|
| committer | Adam Mathes <adam@adammathes.com> | 2026-02-13 21:34:48 -0800 |
| commit | 76cb9c2a39d477a64824a985ade40507e3bbade1 (patch) | |
| tree | 41e997aa9c6f538d3a136af61dae9424db2005a9 /vanilla/node_modules/vite/bin/openChrome.js | |
| parent | 819a39a21ac992b1393244a4c283bbb125208c69 (diff) | |
| download | neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.gz neko-76cb9c2a39d477a64824a985ade40507e3bbade1.tar.bz2 neko-76cb9c2a39d477a64824a985ade40507e3bbade1.zip | |
feat(vanilla): add testing infrastructure and tests (NK-wjnczv)
Diffstat (limited to 'vanilla/node_modules/vite/bin/openChrome.js')
| -rw-r--r-- | vanilla/node_modules/vite/bin/openChrome.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/vanilla/node_modules/vite/bin/openChrome.js b/vanilla/node_modules/vite/bin/openChrome.js new file mode 100644 index 0000000..5a4aa95 --- /dev/null +++ b/vanilla/node_modules/vite/bin/openChrome.js @@ -0,0 +1,68 @@ +/* +Copyright (c) 2015-present, Facebook, Inc. + +This source code is licensed under the MIT license found in the +LICENSE file at +https://github.com/facebook/create-react-app/blob/main/LICENSE +*/ + +/* global Application */ + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +function run(argv) { + const urlToOpen = argv[0] + // Allow requested program to be optional, default to Google Chrome + const programName = argv[1] ?? 'Google Chrome' + + const app = Application(programName) + + if (app.windows.length === 0) { + app.Window().make() + } + + // 1: Looking for tab running debugger then, + // Reload debugging tab if found, then return + const found = lookupTabWithUrl(urlToOpen, app) + if (found) { + found.targetWindow.activeTabIndex = found.targetTabIndex + found.targetTab.reload() + found.targetWindow.index = 1 + app.activate() + return + } + + // 2: Looking for Empty tab + // In case debugging tab was not found + // We try to find an empty tab instead + const emptyTabFound = lookupTabWithUrl('chrome://newtab/', app) + if (emptyTabFound) { + emptyTabFound.targetWindow.activeTabIndex = emptyTabFound.targetTabIndex + emptyTabFound.targetTab.url = urlToOpen + app.activate() + return + } + + // 3: Create new tab + // both debugging and empty tab were not found make a new tab with url + const firstWindow = app.windows[0] + firstWindow.tabs.push(app.Tab({ url: urlToOpen })) + app.activate() +} + +/** + * Lookup tab with given url + */ +function lookupTabWithUrl(lookupUrl, app) { + const windows = app.windows() + for (const window of windows) { + for (const [tabIndex, tab] of window.tabs().entries()) { + if (tab.url().includes(lookupUrl)) { + return { + targetTab: tab, + targetTabIndex: tabIndex + 1, + targetWindow: window, + } + } + } + } +} |
