get-chrome-tabs

1.0.0 • Public • Published

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 Shinnosuke Watanabe

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.0.050latest

Version History

VersionDownloads (Last 7 Days)Published
1.0.050
0.3.12
0.3.02
0.2.02
0.1.02
0.0.02

Package Sidebar

Install

npm i get-chrome-tabs

Weekly Downloads

60

Version

1.0.0

License

ISC

Unpacked Size

7.42 kB

Total Files

5

Last publish

Collaborators

  • shinnn