Skip to content

Get information of the currently opened Chrome tabs, for example URLs and titles

License

Notifications You must be signed in to change notification settings

shinnn/get-chrome-tabs

Repository files navigation

get-chrome-tabs

npm version Build Status Coverage Status

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
  }
] */)();

Installation

Use npm.

npm install get-chrome-tabs

API

const getChromeTabs = require('get-chrome-tabs');

getChromeTabs([option])

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.

option.app

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, ...}, ...]
})();

License

ISC License © 2018 - 2019 Shinnosuke Watanabe