chrome-tool
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
;
The API works like chrome.tabs.* 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
;
The API works like chrome.windows.* 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 windowsreuseThreshold
: Re-uses the current window if its number of tabs is less than or equal
Runtime
;
The API works like chrome.runtime.* 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
;
The API works like chrome.storage.sync.* 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
;
The API works like chrome.browserAction.* 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
;
Functions:
getExtensionInfo(): Promise
Internationalization
;
getString(name: string, substitution?: number | string): string
- Slight improvement over the builtin chrome.i18n.getMessage
- Read the implementation
ContextMenuItem
;
let item = id?: string contexts?: string onclick?: ;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