Get information of the currently opened Chrome tabs, for example URLs and titles
const getChromeTabs = require('get-chrome-tabs');
(async () => getChromeTabs() /* => [
{
windowIndex: 0,
windowVisible: true,
url: 'https://github.com/',
title: 'GitHub',
active: true,
loading: false
},
{
windowIndex: 0,
windowVisible: true,
url: 'https://www.npmjs.com/package/get-chrome-tabs',
title: 'get-chrome-tabs - npm',
active: false,
loading: false
},
{
windowIndex: 1,
windowVisible: true,
url: 'https://example.org/',
title: 'Example Domain',
active: true,
loading: false
}
] */)();
npm install get-chrome-tabs
const getChromeTabs = require('get-chrome-tabs');
option: Object
Return: Promise<Array<Object>>
macOS with JXA support is required.
Each Object
included in the resultant array has the following properties:
- windowIndex
integer
– An index of the window which contains the tab (0
(foremost),1
, ...) - windowVisible
boolean
– Whether the window which contains the tab is visible or not - url
string
– A URL currently opened by the tab - title
string
– The tab title - active
boolean
– Whether the tab is currently selected or not. Each window has one active tab. - loading
boolean
- Whether the tab is loading or not
It will be rejected when Chrome is not running.
Type: string
(either 'canary'
or 'chromium'
)
Instead of Chrome (default), refer to Chrome Canary or Chromium.
// When Chrome is not running but Chrome Canary is running
(async () => {
try {
await getChromeTabs();
} catch (err) {
err.message; //=> 'Tried to get tabs of Chrome, but Chrome is currently not running.'
}
await getChromeTabs({app: 'canary'}); //=> [{windowIndex: 0, windowVisible: true, ...}, ...]
})();
ISC License © 2018 - 2019 Shinnosuke Watanabe