Skip to content

Commit 1363ad7

Browse files
committed
chore: update dependencies cross-spawn & open.
1 parent c227581 commit 1363ad7

File tree

3 files changed

+102
-70
lines changed

3 files changed

+102
-70
lines changed

index.js

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function getBrowserEnv() {
4545

4646
function executeNodeScript(scriptPath, url) {
4747
const extraArgs = process.argv.slice(2);
48-
const child = spawn('node', [scriptPath, ...extraArgs, url], {
48+
const child = spawn(process.execPath, [scriptPath, ...extraArgs, url], {
4949
stdio: 'inherit',
5050
});
5151
child.on('close', code => {
@@ -69,22 +69,43 @@ function startBrowserProcess(browser, url, args) {
6969
// requested a different browser, we can try opening
7070
// Chrome with AppleScript. This lets us reuse an
7171
// existing tab when possible instead of creating a new one.
72-
const shouldTryOpenChromeWithAppleScript =
72+
const shouldTryOpenChromiumWithAppleScript =
7373
process.platform === 'darwin' &&
7474
(typeof browser !== 'string' || browser === OSX_CHROME);
7575

76-
if (shouldTryOpenChromeWithAppleScript) {
77-
try {
78-
// Try our best to reuse existing tab
79-
// on OS X Google Chrome with AppleScript
80-
execSync('ps cax | grep "Google Chrome"');
81-
execSync('osascript openChrome.applescript "' + encodeURI(url) + '"', {
82-
cwd: __dirname,
83-
stdio: 'ignore',
84-
});
85-
return true;
86-
} catch (err) {
87-
// Ignore errors.
76+
if (shouldTryOpenChromiumWithAppleScript) {
77+
// Will use the first open browser found from list
78+
const supportedChromiumBrowsers = [
79+
'Google Chrome Canary',
80+
'Google Chrome Dev',
81+
'Google Chrome Beta',
82+
'Google Chrome',
83+
'Microsoft Edge',
84+
'Brave Browser',
85+
'Vivaldi',
86+
'Chromium',
87+
];
88+
89+
for (let chromiumBrowser of supportedChromiumBrowsers) {
90+
try {
91+
// Try our best to reuse existing tab
92+
// on OSX Chromium-based browser with AppleScript
93+
execSync('ps cax | grep "' + chromiumBrowser + '"');
94+
execSync(
95+
'osascript openChrome.applescript "' +
96+
encodeURI(url) +
97+
'" "' +
98+
chromiumBrowser +
99+
'"',
100+
{
101+
cwd: __dirname,
102+
stdio: 'ignore',
103+
}
104+
);
105+
return true;
106+
} catch (err) {
107+
// Ignore errors.
108+
}
88109
}
89110
}
90111

@@ -131,4 +152,4 @@ function openBrowser(url) {
131152
}
132153
}
133154

134-
module.exports = openBrowser;
155+
module.exports = openBrowser;

openChrome.applescript

Lines changed: 63 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,76 +8,87 @@ LICENSE file in the root directory of this source tree.
88
property targetTab: null
99
property targetTabIndex: -1
1010
property targetWindow: null
11+
property theProgram: "Google Chrome"
1112

1213
on run argv
1314
set theURL to item 1 of argv
1415

15-
tell application "Chrome"
16+
-- Allow requested program to be optional,
17+
-- default to Google Chrome
18+
if (count of argv) > 1 then
19+
set theProgram to item 2 of argv
20+
end if
1621

17-
if (count every window) = 0 then
18-
make new window
19-
end if
22+
using terms from application "Google Chrome"
23+
tell application theProgram
2024

21-
-- 1: Looking for tab running debugger
22-
-- then, Reload debugging tab if found
23-
-- then return
24-
set found to my lookupTabWithUrl(theURL)
25-
if found then
26-
set targetWindow's active tab index to targetTabIndex
27-
tell targetTab to reload
28-
tell targetWindow to activate
29-
set index of targetWindow to 1
30-
return
31-
end if
25+
if (count every window) = 0 then
26+
make new window
27+
end if
28+
29+
-- 1: Looking for tab running debugger
30+
-- then, Reload debugging tab if found
31+
-- then return
32+
set found to my lookupTabWithUrl(theURL)
33+
if found then
34+
set targetWindow's active tab index to targetTabIndex
35+
tell targetTab to reload
36+
tell targetWindow to activate
37+
set index of targetWindow to 1
38+
return
39+
end if
3240

33-
-- 2: Looking for Empty tab
34-
-- In case debugging tab was not found
35-
-- We try to find an empty tab instead
36-
set found to my lookupTabWithUrl("chrome://newtab/")
37-
if found then
38-
set targetWindow's active tab index to targetTabIndex
39-
set URL of targetTab to theURL
40-
tell targetWindow to activate
41-
return
42-
end if
41+
-- 2: Looking for Empty tab
42+
-- In case debugging tab was not found
43+
-- We try to find an empty tab instead
44+
set found to my lookupTabWithUrl("chrome://newtab/")
45+
if found then
46+
set targetWindow's active tab index to targetTabIndex
47+
set URL of targetTab to theURL
48+
tell targetWindow to activate
49+
return
50+
end if
4351

44-
-- 3: Create new tab
45-
-- both debugging and empty tab were not found
46-
-- make a new tab with url
47-
tell window 1
48-
activate
49-
make new tab with properties {URL:theURL}
52+
-- 3: Create new tab
53+
-- both debugging and empty tab were not found
54+
-- make a new tab with url
55+
tell window 1
56+
activate
57+
make new tab with properties {URL:theURL}
58+
end tell
5059
end tell
51-
end tell
60+
end using terms from
5261
end run
5362

5463
-- Function:
5564
-- Lookup tab with given url
5665
-- if found, store tab, index, and window in properties
5766
-- (properties were declared on top of file)
5867
on lookupTabWithUrl(lookupUrl)
59-
tell application "Chrome"
60-
-- Find a tab with the given url
61-
set found to false
62-
set theTabIndex to -1
63-
repeat with theWindow in every window
64-
set theTabIndex to 0
65-
repeat with theTab in every tab of theWindow
66-
set theTabIndex to theTabIndex + 1
67-
if (theTab's URL as string) contains lookupUrl then
68-
-- assign tab, tab index, and window to properties
69-
set targetTab to theTab
70-
set targetTabIndex to theTabIndex
71-
set targetWindow to theWindow
72-
set found to true
68+
using terms from application "Google Chrome"
69+
tell application theProgram
70+
-- Find a tab with the given url
71+
set found to false
72+
set theTabIndex to -1
73+
repeat with theWindow in every window
74+
set theTabIndex to 0
75+
repeat with theTab in every tab of theWindow
76+
set theTabIndex to theTabIndex + 1
77+
if (theTab's URL as string) contains lookupUrl then
78+
-- assign tab, tab index, and window to properties
79+
set targetTab to theTab
80+
set targetTabIndex to theTabIndex
81+
set targetWindow to theWindow
82+
set found to true
83+
exit repeat
84+
end if
85+
end repeat
86+
87+
if found then
7388
exit repeat
7489
end if
7590
end repeat
76-
77-
if found then
78-
exit repeat
79-
end if
80-
end repeat
81-
end tell
91+
end tell
92+
end using terms from
8293
return found
8394
end lookupTabWithUrl

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
"author": "",
4343
"license": "MIT",
4444
"dependencies": {
45-
"colors-cli": "^1.0.13",
46-
"cross-spawn": "^6.0.5",
47-
"open": "^7.0.0"
45+
"colors-cli": "^1.0.32",
46+
"cross-spawn": "^7.0.3",
47+
"open": "^8.4.2"
4848
}
4949
}

0 commit comments

Comments
 (0)