Code Monkey home page Code Monkey logo

then-chrome's Introduction

then-chrome

Build Status Coverage Status npm version

Promise-based chrome api.

usage

var thenChrome = require('then-chrome');

// get tabs list
thenChrome.tabs.query({currentWindow: true})
   .then(console.log); // tabs list

// get all cookies by name   
thenChrome.cookies.getAll({name: 'cookieName'})
   .then(console.log); // cookie list
   
// detect language by tab
thenChrome.tabs.detectLanguage(10)
   .then(console.log); // en
   .catch(console.warn); // catch chrome.runtime.lastError value

Sync methods are wrapped too

var thenChrome = require('then-chrome');

thenChrome.i18n.getMessage('title')
   .then(console.log); // 'extension title'

There is native Promise inside then-chrome by default, but you can use every Thenable lib, compatible with Promises/A+ standart.

var Q = require('q');
var BlueBird = require('bluebird');
var create = require('then-chrome/out/api');

var thenChromeQ = create(Q.Promise); // then-chrome with Q promise inside
var thenChromeBB = create(BlueBird); // then-chrome with bluebird promise inside

install

npm install then-chrome

or

git clone https://github.com/acvetkov/then-chrome.git
cd then-chrome
npm install

build

npm run build

test

npm test

Supported methods

  1. chrome.alarms
  2. chrome.bookmarks
  3. chrome.browserAction
  4. chrome.browsingData
  5. chrome.commands
  6. chrome.contextMenus
  7. chrome.cookies
  8. chrome.debugger
  9. chrome.desktopCapture
  10. chrome.devtools.inspectedWindow
  11. chrome.devtools.network
  12. chrome.devtools.panels
  13. chrome.dial (undocumented API for communication with DIAL-capable devices)
  14. chrome.downloads
  15. chrome.extension
  16. chrome.fontSettings
  17. chrome.gcm
  18. chrome.history
  19. chrome.i18n
  20. chrome.identity
  21. chrome.idle
  22. chrome.instanceID
  23. chrome.management
  24. chrome.notifications
  25. chrome.omnibox
  26. chrome.pageAction
  27. chrome.pageCapture
  28. chrome.permissions
  29. chrome.privacy
  30. chrome.proxy
  31. chrome.runtime
  32. chrome.sessions
  33. chrome.storage
  34. chrome.system.cpu
  35. chrome.system.memory
  36. chrome.system.storage
  37. chrome.tabCapture
  38. chrome.tabs
  39. chrome.topSites
  40. chrome.tts
  41. chrome.webNavigation
  42. chrome.webRequest
  43. chrome.windows

Useful resources

Awesome Browser Extensions And Apps - a curated list of awesome resources for building browser extensions and apps.

then-chrome's People

Contributors

acvetkov avatar aleksandr-oleynikov avatar chanand avatar vitalets avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

then-chrome's Issues

Append lazy getters for methods

Chrome api object is rather big, it takes unnecessary memory for unused methods.
It will be very good to generate promise wrappers by access to them by getters.

For example:

Object.defineProperty(chromeApi.tabs, 'query', {
   get: function() {
      return wrapMethod(chrome.tabs, 'query');
   }
});

Support *.sendMessage methods

chrome.runtime.sendMessage and chrome.tabs.sendMessage methods are not supports.
It will be great wrap it methods to Promise call, which resolves with sendResponse function.

import thenChrome from 'then-chrome';

thenChrome.runtime.sendMessage(message, options)
   .then(response => console.log(response))
   .catch(err => console.error(err));

// equals to

chrome.runtime.sendMessage(message, options, response => {
   if (chrome.runtime.lastError) {
      console.error(chrome.runtime.lastError);
   } else {
      console.log(response);
   }
});

Proxy event channels to thenChrome also (for consistency)

Currently event channels are not in then-chrome.
So I can not write:

thenChrome.alarms.create('alarm');
thenChrome.alarms.onAlarm.addListener(listener);

It gets error:

Uncaught TypeError: Cannot read property 'addListener' of undefined

I need to write:

thenChrome.alarms.create('alarm');
chrome.alarms.onAlarm.addListener(listener);

that looks less consistent.

It would be nice if event channels (like alarms.onAlarm and etc) will be proxied to thenChrome object.

Getting error while calling any method

Hi,

I'm getting error when calling any method like tabs, windows etc.
Ex: I'm calling

chrome.tabs.query({}, function(res){
            console.log(res);
          })

I'm getting error.

Uncaught (in promise): TypeError: Cannot read property 'query' of null

Screen Shot 2020-05-05 at 12 00 14 PM

Please help... Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.