@stolbivi/pirojok
Version:
Some minimalistic library used to build chrome extensions, covers some popular Chrome Extension API
33 lines (32 loc) • 1.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Tabs = void 0;
/**
* A utility class for interacting with Chrome browser tabs.
* Provides methods to query and work with the current tab and all tabs.
*/
var Tabs = /** @class */ (function () {
function Tabs() {
}
/**
* Retrieves the currently active tab in the current window.
* @returns A promise that resolves to the current tab or null if no tab is found.
*/
Tabs.prototype.withCurrentTab = function () {
return new Promise(function (resolve) {
return chrome.tabs.query({
active: true,
currentWindow: true,
}, function (tabs) { return resolve((tabs === null || tabs === void 0 ? void 0 : tabs.length) > 0 ? tabs[0] : null); });
});
};
/**
* Retrieves all tabs across all windows.
* @returns A promise that resolves to an array of all tabs.
*/
Tabs.prototype.withAllTabs = function () {
return new Promise(function (resolve) { return chrome.tabs.query({}, function (tabs) { return resolve(tabs); }); });
};
return Tabs;
}());
exports.Tabs = Tabs;