Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chrome-tool

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chrome-tool - npm Package Compare versions

Comparing version 2.0.2 to 3.0.0

.babelrc

84

dechromeify.js
'use strict';
Object.defineProperty(exports, '__esModule', {
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.alias = alias;
exports.dechromeify = dechromeify;
exports.dechromeifyAll = dechromeifyAll;
/**
* Convert an async Chrome function into one that returns a Promise
* Rename a sync function (closures are faster than .bind)
*/
exports['default'] = dechromeify;
function alias(source, name) {
return function aliased() {
return source[name].apply(source, arguments);
};
}
/**
* Dechromeify whole objects
* Convert an async callback-style function into one that returns a Promise
*/
exports.dechromeifyAll = dechromeifyAll;
function dechromeify(obj, key) {
return function dechromeified() {
var deferred = Promise.defer();
// Add callback as last argument
Array.prototype.push.call(arguments, function callback() {
if (chrome.runtime.lastError) {
deferred.reject(chrome.runtime.lastError);
} else {
deferred.resolve(arguments[0]);
}
function dechromeify(source, name) {
return function promisified() {
var args = Array.prototype.slice.call(arguments);
return new Promise(function (resolve, reject) {
// Add callback as last argument
args.push(function (response) {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else {
resolve(response);
}
});
source[name].apply(source, args);
});
// Execute function
obj[key].apply(obj, arguments);
return deferred.promise;
};
}
function dechromeifyAll(obj) {
var sync = arguments[1] === undefined ? [] : arguments[1];
var target = arguments[2] === undefined ? {} : arguments[2];
/**
* Dechromeify whole objects
*/
function dechromeifyAll(source) {
var sync = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1];
Object.keys(obj).forEach(function (key) {
// Don't overwrite
if (target.hasOwnProperty(key)) {
var result = Object.create(null);
Object.keys(source).forEach(function (name) {
// Function
if (typeof source[name] === 'function') {
var convertFunction = sync.indexOf(name) > -1 ? alias : dechromeify;
result[name] = convertFunction(source, name);
return;
}
// Convert functions/events
if (typeof obj[key] === 'function') {
if (sync.indexOf(key) !== -1) {
target[key] = obj[key].bind(obj);
} else {
target[key] = dechromeify(obj, key);
}
} else if (obj[key] instanceof chrome.Event) {
target[key] = obj[key].addListener.bind(obj[key]);
// Event
if (source[name] instanceof chrome.Event) {
result[name] = alias(source[name], 'addListener');
return;
}
// Anything else
result[name] = source[name];
});
return target;
return result;
}
{
"name": "chrome-tool",
"version": "2.0.2",
"version": "3.0.0",
"description": "Useful functions for creating Chrome apps and extensions",
"keywords": [
"chrome"
],
"keywords": ["chrome"],
"author": "Jannes Meyer <jannes.meyer@gmail.com>",
"license": "GPLv3",
"license": "GPL-3.0",
"repository": "JannesMeyer/chrome-tool",
"main": "chrome-tool.js",
"scripts": {
"prepublish": "make",
"test": "make test"
"prepublish": "make clean && make",
"test": "./node_modules/.bin/jasmine"
},
"main": "index.js",
"dependencies": {
"object.assign": "2.x"
},
"devDependencies": {
"babel": "x",
"jasmine": "2.x"
"babel-cli": "^6.3.26",
"babel-plugin-transform-flow-strip-types": "^6.4.0",
"babel-plugin-typecheck": "^3.6.1",
"babel-preset-es2015": "^6.3.13",
"jasmine": "^2.4.1"
}
}

@@ -7,2 +7,234 @@ # chrome-tool

Documentation coming soon…
Compatible with Chrome 45 and higher. For older versions you might need to polyfill these:
- Object.assign
- Promise
- Map
Installation:
npm install chrome-tool --save
## Tabs
```js
import { Tabs } from 'chrome-tool';
```
The API works like [chrome.tabs.\*](https://developer.chrome.com/extensions/tabs#toc) except that it returns promises.
Functions:
- `Tabs.get(tabId: number): Promise`
- `Tabs.getCurrent(): Promise`
- `Tabs.create(createProperties): Promise`
- `Tabs.duplicate(tabId: number): Promise`
- `Tabs.query(queryInfo): Promise`
- `Tabs.highlight(highlightInfo): Promise`
- `Tabs.update(tabId?: number, updateProperties): Promise`
- `Tabs.move(tabIds: number | number[], moveProperties): Promise`
- `Tabs.reload(tabId?: number, reloadProperties?): Promise`
- `Tabs.remove(tabIds: number | number[]): Promise`
- `Tabs.detectLanguage(tabId?: number): Promise`
- `Tabs.captureVisibleTab(windowId?: number, options?): Promise`
- `Tabs.executeScript(tabId?: number, details): Promise`
- `Tabs.insertCSS(tabId?: number, object details): Promise`
- `Tabs.setZoom(tabId?: number, zoomFactor: number): Promise`
- `Tabs.getZoom(tabId?: number): Promise`
- `Tabs.setZoomSettings(tabId?: number, zoomSettings): Promise`
- `Tabs.getZoomSettings(tabId?: number): Promise`
Events:
- `Tabs.onCreated(callback): void`
- `Tabs.onUpdated(callback): void`
- `Tabs.onMoved(callback): void`
- `Tabs.onSelectionChanged(callback): void`
- `Tabs.onActiveChanged(callback): void`
- `Tabs.onActivated(callback): void`
- `Tabs.onHighlightChanged(callback): void`
- `Tabs.onHighlighted(callback): void`
- `Tabs.onDetached(callback): void`
- `Tabs.onAttached(callback): void`
- `Tabs.onRemoved(callback): void`
- `Tabs.onReplaced(callback): void`
- `Tabs.onZoomChange(callback): void`
Custom functions:
- `Tabs.getHighlighted(): Promise`
- `Tabs.getActive(): Promise`
- `Tabs.open(openerTab: { id: number }, url: string): Promise`
- `Tabs.count(): Promise`
- `Tabs.moveHighlighted(direction: number): Promise`
- `Tabs.moveToNewWindow(tabs: Tab[], incognito: boolean): Promise`
- `Tabs.moveToWindow(tabs: Tab[], targetWindowId: number): Promise`
- `Tabs.closeOthers(): Promise`
## Windows
```js
import { Windows } from 'chrome-tool';
```
The API works like [chrome.windows.\*](https://developer.chrome.com/extensions/windows#toc) except that it returns promises.
Functions:
- `Windows.get(windowId, getInfo?): Promise`
- `Windows.getCurrent(getInfo?): Promise`
- `Windows.getLastFocused(getInfo?): Promise`
- `Windows.getAll(getInfo?): Promise`
- `Windows.create(createData?): Promise`
- `Windows.update(windowId, updateInfo): Promise`
- `Windows.remove(windowId): Promise`
Events:
- `Windows.onCreated(callback): void`
- `Windows.onRemoved(callback): void`
- `Windows.onFocusChanged(callback): void`
Custom functions:
- `Windows.open(windows: string[][], reuseThreshold = 1): void`
- `windows`: 2-dimensional array of URLs to open as windows
- `reuseThreshold`: Re-uses the current window if its number of tabs is less than or equal
## Runtime
```js
import { Runtime } from 'chrome-tool';
```
The API works like [chrome.runtime.\*](https://developer.chrome.com/extensions/runtime#toc) except that it returns promises.
Functions:
- `Runtime.getBackgroundPage(): Promise`
- `Runtime.openOptionsPage(): Promise`
- `Runtime.getManifest(): any`
- `Runtime.getURL(string path): string`
- `Runtime.setUninstallURL(url: string): Promise`
- `Runtime.reload(): void`
- `Runtime.requestUpdateCheck(): Promise`
- `Runtime.restart(): void`
- `Runtime.connect(extensionId?: string, connectInfo?): Port`
- `Runtime.connectNative(application: string): Port`
- `Runtime.sendNativeMessage(application: string, message): Promise`
- `Runtime.getPlatformInfo(): Promise`
- `Runtime.getPackageDirectoryEntry(): Promise`
Modified functions (these work differently than described in Chrome's docs):
- `sendMessage(operation: string, message): Promise`
- `onMessage(operation: string, callback): void`
Events:
- `Runtime.onStartup(callback): void`
- `Runtime.onInstalled(callback): void`
- `Runtime.onSuspend(callback): void`
- `Runtime.onSuspendCanceled(callback): void`
- `Runtime.onUpdateAvailable(callback): void`
- `Runtime.onConnect(callback): void`
- `Runtime.onConnectExternal(callback): void`
- `Runtime.onMessageExternal(callback): void`
- `Runtime.onRestartRequired(callback): void`
## StorageSync
```js
import { StorageSync } from 'chrome-tool';
```
The API works like [chrome.storage.sync.\*](https://developer.chrome.com/extensions/storage#toc) except that it returns promises.
Functions:
- `StorageSync.get(keys?: string | string[] | object): Promise`
- `StorageSync.getBytesInUse(keys?: string | string[]): Promise`
- `StorageSync.set(items): Promise`
- `StorageSync.remove(keys: string | string[]): Promise`
- `StorageSync.clear(): Promise`
Events:
- `StorageSync.onChanged(callback): void`
## BrowserAction
```js
import { BrowserAction } from 'chrome-tool';
```
The API works like [chrome.browserAction.\*](https://developer.chrome.com/extensions/browserAction#toc) except that it returns promises.
Functions:
- `BrowserAction.getTitle(details: object): Promise`
- `BrowserAction.getPopup(details: object): Promise`
- `BrowserAction.getBadgeText(details: object): Promise`
- `BrowserAction.getBadgeBackgroundColor(details: object): Promise`
- `BrowserAction.setTitle(details: object): void`
- `BrowserAction.setPopup(details: object): void`
- `BrowserAction.setBadgeText(details: object): void`
- `BrowserAction.setBadgeBackgroundColor(details: object): void`
- `BrowserAction.setIcon(details: object): Promise`
- `BrowserAction.enable(tabId?: number): void`
- `BrowserAction.disable(tabId?: number): void`
Events:
- `BrowserAction.onClicked(callback): void`
## Management
```js
import { getExtensionInfo } from 'chrome-tool/management';
```
Functions:
- `getExtensionInfo(): Promise`
- [chrome.managment.getSelf()](https://developer.chrome.com/extensions/management#method-getSelf)
## Internationalization
```js
import { getString } from 'chrome-tool/i18n';
```
- `getString(name: string, substitution?: number | string): string`
- Slight improvement over the builtin [chrome.i18n.getMessage](https://developer.chrome.com/extensions/i18n#toc)
- [Read the implementation](https://github.com/JannesMeyer/chrome-tool/blob/fcd8ff6f8eb1a6745dc3f4464cdd5ddd42a263e7/src/i18n.js)
## ContextMenuItem
```js
import { ContextMenuItem } from 'chrome-tool/i18n';
```
[chrome.contextMenus.\*](https://developer.chrome.com/extensions/contextMenus#toc)
```js
let item = new ContextMenuItem(id?: string, contexts?: string[], onclick?: function);
item.show();
item.hide();
item.setVisible(visibility: boolean);
```
## Contributing
Download source and compile:
git clone git@github.com:[USERNAME]/chrome-tool.git
make
Watch for changes and recompile:
make watch
Run tests:
npm test
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.es5.js"
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
]
],
"stopSpecOnExpectationFailure": false,
"random": false
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc