توضیحات
از API chrome.tabs برای تعامل با سیستم تبهای مرورگر استفاده کنید. میتوانید از این API برای ایجاد، تغییر و تنظیم مجدد تبها در مرورگر استفاده کنید.
نمای کلی
API تبها نه تنها امکاناتی برای دستکاری و مدیریت تبها ارائه میدهد، بلکه میتواند زبان تب را نیز تشخیص دهد، از آن اسکرینشات بگیرد و با اسکریپتهای محتوای تب ارتباط برقرار کند .
مجوزها
اکثر ویژگیها برای استفاده به هیچ مجوزی نیاز ندارند. برای مثال: ایجاد یک تب جدید، بارگذاری مجدد یک تب، رفتن به یک URL دیگر و غیره.
سه مجوز وجود دارد که توسعهدهندگان باید هنگام کار با Tabs API از آنها آگاه باشند.
- مجوز «زبانهها»
- این مجوز به فضای نام
chrome.tabsدسترسی نمیدهد. در عوض، به یک افزونه این امکان را میدهد کهtabs.query()را در برابر چهار ویژگی حساس در نمونههایtabs.Tabفراخوانی کند:url،pendingUrl،titleوfavIconUrl. - مجوزهای میزبان
- مجوزهای میزبان به یک افزونه اجازه میدهند تا چهار ویژگی حساس
tabs.Tabیک تب منطبق را بخواند و از آنها پرسوجو کند. آنها همچنین میتوانند با استفاده از روشهایی مانندtabs.captureVisibleTab()،tabs.executeScript()،tabs.insertCSS()وtabs.removeCSS()مستقیماً با تبهای منطبق تعامل داشته باشند. - مجوز "activeTab"
-
activeTabدر پاسخ به فراخوانی کاربر، مجوز میزبانی موقت را برای تب فعلی به افزونه اعطا میکند. برخلاف مجوزهای میزبانی،activeTabهیچ هشداری ایجاد نمیکند.
مانیفست
در زیر مثالهایی از نحوهی اعلان هر مجوز در مانیفست آمده است:
{
"name": "My extension",
...
"permissions": [
"tabs"
],
...
}
{
"name": "My extension",
...
"host_permissions": [
"http://*/*",
"https://*/*"
],
...
}
{
"name": "My extension",
...
"permissions": [
"activeTab"
],
...
}
موارد استفاده
بخشهای زیر برخی از موارد استفاده رایج را نشان میدهند.
باز کردن صفحه افزونه در یک تب جدید
یک الگوی رایج برای افزونهها این است که پس از نصب افزونه، یک صفحه معرفی در یک تب جدید باز میشود. مثال زیر نحوه انجام این کار را نشان میدهد.
پسزمینه.js:
chrome.runtime.onInstalled.addListener(({reason}) => {
if (reason === 'install') {
chrome.tabs.create({
url: "onboarding.html"
});
}
});
دریافت برگه فعلی
این مثال نشان میدهد که چگونه سرویس ورکر یک افزونه میتواند تب فعال را از پنجرهی متمرکز فعلی (یا آخرین پنجرهی متمرکز، اگر هیچ پنجرهی کرومی متمرکز نباشد) بازیابی کند. این معمولاً میتواند به عنوان تب فعلی کاربر در نظر گرفته شود.
async function getCurrentTab() {
let queryOptions = { active: true, lastFocusedWindow: true };
// `tab` will either be a `tabs.Tab` instance or `undefined`.
let [tab] = await chrome.tabs.query(queryOptions);
return tab;
}
function getCurrentTab(callback) {
let queryOptions = { active: true, lastFocusedWindow: true };
chrome.tabs.query(queryOptions, ([tab]) => {
if (chrome.runtime.lastError)
console.error(chrome.runtime.lastError);
// `tab` will either be a `tabs.Tab` instance or `undefined`.
callback(tab);
});
}
بیصدا کردن تب مشخصشده
این مثال نشان میدهد که چگونه یک افزونه میتواند حالت بیصدا را برای یک تب مشخص تغییر دهد.
async function toggleMuteState(tabId) {
const tab = await chrome.tabs.get(tabId);
const muted = !tab.mutedInfo.muted;
await chrome.tabs.update(tabId, {muted});
console.log(`Tab ${tab.id} is ${muted ? "muted" : "unmuted"}`);
}
function toggleMuteState(tabId) {
chrome.tabs.get(tabId, async (tab) => {
let muted = !tab.mutedInfo.muted;
await chrome.tabs.update(tabId, { muted });
console.log(`Tab ${tab.id} is ${ muted ? "muted" : "unmuted" }`);
});
}
انتقال تب فعلی به اولین موقعیت هنگام کلیک
این مثال نحوه جابجایی یک تب را در حین انجام یا عدم انجام عمل کشیدن نشان میدهد. اگرچه این مثال از chrome.tabs.move استفاده میکند، میتوانید از الگوی انتظار مشابه برای سایر فراخوانیهایی که تبها را در حین انجام کشیدن تغییر میدهند، استفاده کنید.
chrome.tabs.onActivated.addListener(moveToFirstPosition);
async function moveToFirstPosition(activeInfo) {
try {
await chrome.tabs.move(activeInfo.tabId, {index: 0});
console.log("Success.");
} catch (error) {
if (error == "Error: Tabs cannot be edited right now (user may be dragging a tab).") {
setTimeout(() => moveToFirstPosition(activeInfo), 50);
} else {
console.error(error);
}
}
}
chrome.tabs.onActivated.addListener(moveToFirstPositionMV2);
function moveToFirstPositionMV2(activeInfo) {
chrome.tabs.move(activeInfo.tabId, { index: 0 }, () => {
if (chrome.runtime.lastError) {
const error = chrome.runtime.lastError;
if (error == "Error: Tabs cannot be edited right now (user may be dragging a tab).") {
setTimeout(() => moveToFirstPositionMV2(activeInfo), 50);
} else {
console.error(error);
}
} else {
console.log("Success.");
}
});
}
ارسال پیام به اسکریپت محتوای تب انتخاب شده
این مثال نشان میدهد که چگونه سرویس ورکر یک افزونه میتواند با استفاده از tabs.sendMessage() با اسکریپتهای محتوا در تبهای خاص مرورگر ارتباط برقرار کند.
function sendMessageToActiveTab(message) {
const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
const response = await chrome.tabs.sendMessage(tab.id, message);
// TODO: Do something with the response.
}
نمونههای افزونه
برای مشاهدهی دموهای بیشتر از افزونههای Tabs API، هر یک از موارد زیر را بررسی کنید:
انواع
MutedInfo
وضعیت بیصدا بودن تب و دلیل آخرین تغییر وضعیت.
خواص
- شناسه افزونه
رشته اختیاری
شناسه افزونهای که وضعیت بیصدا را تغییر داده است. اگر آخرین تغییر وضعیت بیصدا به دلیل یک افزونه نبوده باشد، تنظیم نمیشود.
- خاموش
بولی
اینکه آیا زبانه بیصدا شده است (از پخش صدا جلوگیری میشود). حتی اگر زبانه پخش نشده باشد یا در حال حاضر صدایی پخش نکند، ممکن است بیصدا باشد. معادل این است که آیا نشانگر صدای «بیصدا» نمایش داده میشود یا خیر.
- دلیل
دلیل اطلاعات خاموش اختیاری است
دلیل بیصدا یا بیصدا کردن تب. اگر وضعیت بیصدا کردن تب هرگز تغییر نکرده باشد، تنظیم نمیشود.
MutedInfoReason
رویدادی که باعث تغییر وضعیت بیصدا شده است.
شمارشی
"کاربر" "گرفتن" "امتداد"
یک عمل ورودی کاربر، حالت بیصدا را تنظیم کرد.
ضبط برگه آغاز شد و باعث تغییر وضعیت بیصدا شد.
یک افزونه که با فیلد extensionId شناسایی میشود، حالت بیصدا را تنظیم میکند.
Tab
خواص
- فعال
بولی
اینکه آیا تب در پنجرهاش فعال است یا خیر. لزوماً به این معنی نیست که پنجره در حالت فوکوس قرار دارد.
- قابل شنیدن
بولی اختیاری
کروم ۴۵+اینکه آیا زبانه در چند ثانیه گذشته صدایی تولید کرده است یا خیر (اما اگر بیصدا نیز باشد، ممکن است شنیده نشود). معادل این است که آیا نشانگر «صدای بلندگو» نمایش داده میشود یا خیر.
- خودکارقابل حذف
بولی
کروم ۵۴+اینکه آیا مرورگر میتواند در صورت کمبود منابع، تب را بهطور خودکار حذف کند یا خیر.
- دور انداخته شده
بولی
کروم ۵۴+اینکه آیا تب حذف شده است یا خیر. تب حذف شده، تبی است که محتوای آن از حافظه حذف شده است، اما هنوز در نوار تبها قابل مشاهده است. محتوای آن دفعه بعد که فعال شود، دوباره بارگذاری میشود.
- آدرس آیکون مورد علاقه
رشته اختیاری
آدرس اینترنتی (URL) فاوآیکون تب. این ویژگی فقط در صورتی وجود دارد که افزونه مجوز
"tabs"یا مجوزهای میزبان برای صفحه را داشته باشد. همچنین اگر تب در حال بارگیری باشد، میتواند یک رشته خالی باشد. - یخ زده
بولی
کروم ۱۳۲+اینکه آیا تب قفل شده است یا خیر. یک تب قفل شده نمیتواند وظایفی از جمله کنترلکنندههای رویداد یا تایمرها را اجرا کند. در نوار تبها قابل مشاهده است و محتوای آن در حافظه بارگذاری میشود. هنگام فعال شدن، قفل آن باز میشود.
- شناسه گروه
شماره
کروم ۸۸+شناسه گروهی که تب به آن تعلق دارد.
- ارتفاع
شماره اختیاری
ارتفاع تب بر حسب پیکسل.
- برجسته شده
بولی
اینکه آیا برگه برجسته شده است یا خیر.
- شناسه
شماره اختیاری
شناسهی تب. شناسههای تب در یک جلسهی مرورگر منحصر به فرد هستند. تحت برخی شرایط، ممکن است به یک تب شناسهای اختصاص داده نشود؛ برای مثال، هنگام جستجوی تبهای خارجی با استفاده از API
sessions، در این صورت ممکن است شناسهی جلسه وجود داشته باشد. شناسهی تب همچنین میتواند برای برنامهها و پنجرههای devtools رویchrome.tabs.TAB_ID_NONEتنظیم شود. - ناشناس
بولی
اینکه آیا برگه در پنجره ناشناس است یا خیر.
- شاخص
شماره
اندیس مبتنی بر صفرِ تبِ درون پنجرهاش.
- آخرین دسترسی
شماره
کروم ۱۲۱+آخرین باری که تب در پنجره خود فعال شده است، به عنوان تعداد میلی ثانیه از زمان epoch.
- اطلاعات بیصدا
اطلاعات خاموش اختیاری
کروم ۴۶+وضعیت بیصدا بودن تب و دلیل آخرین تغییر وضعیت.
- تب آی دی بازکننده
شماره اختیاری
شناسهی برگهای که این برگه را باز کرده است، در صورت وجود. این ویژگی فقط در صورتی وجود دارد که برگهی بازکننده هنوز وجود داشته باشد.
- در انتظارآدرس
رشته اختیاری
کروم ۷۹+آدرس اینترنتی (URL) که تب قبل از ثبت نهایی به آن هدایت میشود. این ویژگی فقط در صورتی وجود دارد که افزونه مجوز
"tabs"را داشته باشد یا مجوزهای میزبان برای صفحه داشته باشد و یک پیمایش در حال انتظار وجود داشته باشد. - سنجاق شده
بولی
اینکه آیا برگه پین شده است یا خیر.
- انتخاب شده
بولی
منسوخ شدهلطفا از
tabs.Tab.highlightedاستفاده کنید.اینکه آیا برگه انتخاب شده است یا خیر.
- شناسه جلسه
رشته اختیاری
شناسهی جلسه (session ID) که برای شناسایی منحصر به فرد یک برگه (tab) که از API
sessionsAPI) به دست آمده است، استفاده میشود. - splitViewId
شماره اختیاری
کروم ۱۴۵+شناسه نمای تقسیمشدهای که تب به آن تعلق دارد.
- وضعیت
وضعیت برگه ( اختیاری)
وضعیت بارگذاری برگه.
- عنوان
رشته اختیاری
عنوان برگه. این ویژگی فقط در صورتی وجود دارد که افزونه مجوز
"tabs"را داشته باشد یا مجوزهای میزبان برای صفحه داشته باشد. - آدرس اینترنتی
رشته اختیاری
آخرین URL ثبتشدهی فریم اصلی تب. این ویژگی فقط در صورتی وجود دارد که افزونه مجوز
"tabs"یا مجوزهای میزبان برای صفحه را داشته باشد. اگر تب هنوز ثبت نشده باشد، میتواند یک رشتهی خالی باشد. همچنین بهTab.pendingUrlمراجعه کنید. - عرض
شماره اختیاری
عرض تب بر حسب پیکسل.
- شناسه پنجره
شماره
شناسهی پنجرهای که حاوی تب است.
TabStatus
وضعیت بارگذاری برگه.
شمارشی
"تخلیه شده" "در حال بارگذاری" "کامل"
WindowType
نوع پنجره.
شمارشی
"عادی" "پاپآپ" "پانل" "برنامه" "ابزارهای توسعه"
ZoomSettings
تعریف میکند که تغییرات بزرگنمایی در یک تب چگونه و در چه محدودهای مدیریت شوند.
خواص
- پیش فرضفاکتور بزرگنمایی
شماره اختیاری
کروم ۴۳+برای برگرداندن سطح بزرگنمایی پیشفرض برای تب فعلی در فراخوانیهای tabs.getZoomSettings استفاده میشود.
- حالت
حالت تنظیمات زوم اختیاری است
نحوه مدیریت تغییرات بزرگنمایی را تعریف میکند، یعنی کدام موجودیت مسئول مقیاسبندی واقعی صفحه است؛ پیشفرض روی
automaticاست. - محدوده
تنظیمات زوم و محدوده اختیاری
مشخص میکند که آیا تغییرات بزرگنمایی برای مبدأ صفحه باقی میمانند یا فقط در این برگه اعمال میشوند؛ در حالت
automatic، پیشفرض بهper-originو در غیر این صورتper-tab.
ZoomSettingsMode
نحوه مدیریت تغییرات بزرگنمایی را تعریف میکند، یعنی کدام موجودیت مسئول مقیاسبندی واقعی صفحه است؛ پیشفرض روی automatic است.
شمارشی
"خودکار" "دستی" "معلول"
تغییرات بزرگنمایی به طور خودکار توسط مرورگر انجام میشود.
مدیریت خودکار تغییرات زوم را لغو میکند. رویداد onZoomChange همچنان ارسال خواهد شد و این وظیفه افزونه است که به این رویداد گوش دهد و صفحه را به صورت دستی مقیاسبندی کند. این حالت از زوم per-origin پشتیبانی نمیکند و بنابراین تنظیمات زوم scope نادیده میگیرد و per-tab را در نظر میگیرد.
تمام بزرگنماییهای برگه را غیرفعال میکند. برگه به سطح بزرگنمایی پیشفرض برمیگردد و تمام تغییرات بزرگنمایی انجام شده نادیده گرفته میشوند.
ZoomSettingsScope
مشخص میکند که آیا تغییرات بزرگنمایی برای مبدأ صفحه باقی میمانند یا فقط در این برگه اعمال میشوند؛ در حالت automatic ، پیشفرض به per-origin و در غیر این صورت per-tab .
شمارشی
"به ازای هر مبدا" "به ازای هر برگه"
تغییرات بزرگنمایی در مبدأ صفحه بزرگنمایی شده باقی میمانند، یعنی تمام تبهای دیگری که به همان مبدأ پیمایش میشوند نیز بزرگنمایی میشوند. علاوه بر این، تغییرات بزرگنمایی به ازای per-origin با مبدأ ذخیره میشوند، به این معنی که هنگام پیمایش به صفحات دیگر در همان مبدأ، همه آنها به همان ضریب بزرگنمایی بزرگنمایی میشوند. دامنه per-origin فقط در حالت automatic در دسترس است.
تغییرات بزرگنمایی فقط در این برگه اعمال میشوند و تغییرات بزرگنمایی در برگههای دیگر، تاثیری بر بزرگنمایی این برگه ندارد. همچنین، تغییرات بزرگنمایی per-tab در پیمایش بازنشانی میشوند؛ پیمایش یک برگه همیشه صفحات را با ضرایب بزرگنمایی per-origin بارگذاری میکند.
خواص
MAX_CAPTURE_VISIBLE_TAB_CALLS_PER_SECOND
حداکثر تعداد دفعاتی که captureVisibleTab میتواند در هر ثانیه فراخوانی شود. captureVisibleTab گران است و نباید زیاد فراخوانی شود.
ارزش
۲
SPLIT_VIEW_ID_NONE
شناسهای که نشاندهندهی عدم وجود تب تقسیمشده است.
ارزش
-1
TAB_ID_NONE
شناسهای که نشاندهندهی عدم وجود تب مرورگر است.
ارزش
-1
TAB_INDEX_NONE
اندیسی که نشاندهندهی عدم وجود اندیس تب در tab_strip است.
ارزش
-1
روشها
captureVisibleTab()
chrome.tabs.captureVisibleTab(
windowId?: number,
options?: ImageDetails,
callback?: function,
): Promise<string>
ناحیه قابل مشاهده تب فعال فعلی در پنجره مشخص شده را ضبط میکند. برای فراخوانی این روش، افزونه باید مجوز <all_urls> یا مجوز activeTab را داشته باشد. علاوه بر سایتهایی که افزونهها معمولاً میتوانند به آنها دسترسی داشته باشند، این روش به افزونهها اجازه میدهد سایتهای حساسی را که در غیر این صورت محدود شدهاند، از جمله صفحات chrome:-scheme، صفحات سایر افزونهها و URLهای data:، ضبط کنند. این سایتهای حساس فقط با مجوز activeTab قابل ضبط هستند. URLهای فایل فقط در صورتی قابل ضبط هستند که افزونه به فایل دسترسی داشته باشد.
پارامترها
- شناسه پنجره
شماره اختیاری
پنجره هدف. به طور پیشفرض پنجره فعلی .
- گزینهها
جزئیات تصویر اختیاری
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(dataUrl: string) => void
- آدرس داده
رشته
یک URL داده که تصویری از ناحیه قابل مشاهده تب گرفته شده را رمزگذاری میکند. ممکن است برای نمایش به ویژگی 'src' یک عنصر
imgHTML اختصاص داده شود.
بازگشتها
قول<string>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
connect()
chrome.tabs.connect(
tabId: number,
connectInfo?: object,
): runtime.Port
به اسکریپت(های) محتوا در تب مشخص شده متصل میشود. رویداد runtime.onConnect در هر اسکریپت محتوا که در تب مشخص شده برای افزونه فعلی اجرا میشود، اجرا میشود. برای جزئیات بیشتر، به پیامرسانی اسکریپت محتوا مراجعه کنید.
پارامترها
- شناسه برگه
شماره
- اطلاعات اتصال
شیء اختیاری
- شناسه سند
رشته اختیاری
کروم ۱۰۶+به جای تمام فریمهای موجود در برگه، یک پورت را به یک سند خاص که توسط
documentIdمشخص شده است، باز کنید. - شناسه قاب
شماره اختیاری
به جای تمام فریمهای موجود در برگه، یک پورت را برای یک فریم خاص که توسط
frameIdمشخص شده است، باز کنید. - نام
رشته اختیاری
برای اسکریپتهای محتوایی که منتظر رویداد اتصال هستند، به onConnect ارسال میشود.
بازگشتها
پورتی که میتواند برای ارتباط با اسکریپتهای محتوایی که در تب مشخص شده اجرا میشوند، استفاده شود. رویداد
runtime.Portمربوط به پورت در صورتی اجرا میشود که تب بسته شود یا وجود نداشته باشد.
create()
chrome.tabs.create(
createProperties: object,
callback?: function,
): Promise<Tab>
یک برگه جدید ایجاد میکند.
پارامترها
- ایجاد ویژگیها
شیء
- فعال
بولی اختیاری
اینکه آیا تب باید به عنوان تب فعال در پنجره انتخاب شود یا خیر. تاثیری بر فوکوس بودن پنجره ندارد (به
windows.updateمراجعه کنید). مقدار پیشفرضtrueاست. - شاخص
شماره اختیاری
موقعیتی که تب باید در پنجره بگیرد. مقدار ارائه شده بین صفر و تعداد تبهای موجود در پنجره محدود میشود.
- تب آی دی بازکننده
شماره اختیاری
شناسهی برگهای که این برگه را باز کرده است. در صورت مشخص شدن، برگهی بازکننده باید در همان پنجرهای باشد که برگهی جدید ایجاد شده است.
- سنجاق شده
بولی اختیاری
اینکه آیا تب باید پین شود یا خیر. مقدار پیشفرض
falseاست. - انتخاب شده
بولی اختیاری
منسوخ شدهلطفا از فعال استفاده کنید.
اینکه آیا تب مورد نظر باید به عنوان تب انتخاب شده در پنجره انتخاب شود یا خیر. مقدار پیشفرض
trueاست. - آدرس اینترنتی
رشته اختیاری
نشانی اینترنتی (URL) که در ابتدا باید به آن بروید. نشانیهای اینترنتی کاملاً معتبر باید شامل یک طرح باشند (مثلاً «http://www.google.com» نه «www.google.com»). نشانیهای اینترنتی نسبی نسبت به صفحه فعلی در افزونه هستند. پیشفرض روی صفحه برگه جدید است.
- شناسه پنجره
شماره اختیاری
پنجرهای که در آن تب جدید ایجاد میشود. پیشفرض پنجره فعلی است.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(tab: Tab) => void
- تب
برگه ایجاد شده.
بازگشتها
قول بده< تب >
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
detectLanguage()
chrome.tabs.detectLanguage(
tabId?: number,
callback?: function,
): Promise<string>
زبان اصلی محتوای یک برگه را تشخیص میدهد.
پارامترها
- شناسه برگه
شماره اختیاری
به طور پیشفرض روی برگه فعال پنجره فعلی قرار میگیرد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(language: string) => void
- زبان
رشته
یک کد زبان ISO مانند
enیاfr. برای لیست کاملی از زبانهای پشتیبانی شده توسط این روش، به kLanguageInfoTable مراجعه کنید. ستونهای دوم تا چهارم بررسی میشوند و اولین مقدار غیر NULL بازگردانده میشود، به جز چینی ساده شده کهzh-CNبرای آن بازگردانده میشود. برای یک زبان ناشناخته/تعریف نشده،undبازگردانده میشود.
بازگشتها
قول<string>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
discard()
chrome.tabs.discard(
tabId?: number,
callback?: function,
): Promise<Tab | undefined>
یک تب را از حافظه حذف میکند. تبهای حذف شده هنوز در نوار تبها قابل مشاهده هستند و هنگام فعال شدن دوباره بارگذاری میشوند.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که قرار است حذف شود. در صورت مشخص شدن، برگه حذف میشود، مگر اینکه فعال باشد یا از قبل حذف شده باشد. در صورت حذف، مرورگر کماهمیتترین برگه را حذف میکند. اگر هیچ برگهی قابل حذفی وجود نداشته باشد، این روش ممکن است با شکست مواجه شود.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(tab?: Tab) => void
- تب
تب اختیاری
تب حذفشده، اگر با موفقیت حذف شده باشد؛ در غیر این صورت تعریف نشده است.
بازگشتها
قول< تب | تعریف نشده>
کروم ۸۸+پس از اتمام عمل برطرف میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
duplicate()
chrome.tabs.duplicate(
tabId: number,
callback?: function,
): Promise<Tab | undefined>
یک برگه را کپی میکند.
پارامترها
- شناسه برگه
شماره
شناسهی برگهای که قرار است کپی شود.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(tab?: Tab) => void
بازگشتها
قول< تب | تعریف نشده>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
executeScript()
chrome.tabs.executeScript(
tabId?: number,
details: InjectDetails,
callback?: function,
): Promise<any[] | undefined>
در Manifest V3 با scripting.executeScript جایگزین شده است.
کد جاوا اسکریپت را به یک صفحه تزریق میکند. برای جزئیات بیشتر، به بخش تزریق برنامهنویسیشده در سند اسکریپتهای محتوا مراجعه کنید.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که اسکریپت در آن اجرا میشود؛ بهطور پیشفرض روی برگهی فعال پنجرهی فعلی قرار دارد.
- جزئیات
جزئیات اسکریپتی که قرار است اجرا شود. یا کد یا ویژگی فایل باید تنظیم شوند، اما هر دو را نمیتوان همزمان تنظیم کرد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(result?: any[]) => void
- نتیجه
هر [] اختیاری
نتیجه اسکریپت در هر فریم تزریق شده.
بازگشتها
قول <any[] | undefined>
کروم ۸۸+پس از اجرای تمام کدهای جاوا اسکریپت، برطرف میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
get()
chrome.tabs.get(
tabId: number,
callback?: function,
): Promise<Tab>
جزئیات مربوط به تب مشخص شده را بازیابی میکند.
پارامترها
- شناسه برگه
شماره
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(tab: Tab) => void
- تب
بازگشتها
قول بده< تب >
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
getAllInWindow()
chrome.tabs.getAllInWindow(
windowId?: number,
callback?: function,
): Promise<Tab[]>
لطفا از tabs.query {windowId: windowId} استفاده کنید.
جزئیات مربوط به تمام تبهای موجود در پنجرهی مشخص شده را دریافت میکند.
پارامترها
- شناسه پنجره
شماره اختیاری
پیشفرض روی پنجرهی فعلی .
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(tabs: Tab[]) => void
- زبانهها
تب []
بازگشتها
قول بده< تب []>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
getCurrent()
chrome.tabs.getCurrent(
callback?: function,
): Promise<Tab | undefined>
تبی را که این فراخوانی اسکریپت از آن انجام میشود، برمیگرداند. اگر از یک زمینه غیر از تب (مثلاً یک صفحه پسزمینه یا نمای پاپآپ) فراخوانی شود، undefined برمیگرداند.
پارامترها
بازگشتها
قول< تب | تعریف نشده>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
getSelected()
chrome.tabs.getSelected(
windowId?: number,
callback?: function,
): Promise<Tab>
لطفا از tabs.query {active: true} استفاده کنید.
تبی را که در پنجره مشخص شده انتخاب شده است، برمیگرداند.
پارامترها
- شناسه پنجره
شماره اختیاری
پیشفرض روی پنجرهی فعلی .
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(tab: Tab) => void
- تب
بازگشتها
قول بده< تب >
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
getZoom()
chrome.tabs.getZoom(
tabId?: number,
callback?: function,
): Promise<number>
ضریب بزرگنمایی فعلی یک تب مشخص شده را دریافت میکند.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که قرار است ضریب بزرگنمایی فعلی از آن گرفته شود؛ بهطور پیشفرض روی برگهی فعال پنجرهی فعلی قرار دارد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(zoomFactor: number) => void
- زوم فاکتور
شماره
ضریب بزرگنمایی فعلی تب.
بازگشتها
قول<number>
کروم ۸۸+با ضریب بزرگنمایی فعلی برگه پس از واکشی آن، حل میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
getZoomSettings()
chrome.tabs.getZoomSettings(
tabId?: number,
callback?: function,
): Promise<ZoomSettings>
تنظیمات بزرگنمایی فعلی یک تب مشخص شده را دریافت میکند.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که تنظیمات بزرگنمایی فعلی از آن دریافت میشود؛ بهطور پیشفرض روی برگهی فعال پنجرهی فعلی قرار دارد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(zoomSettings: ZoomSettings) => void
- تنظیمات زوم
تنظیمات بزرگنمایی فعلی برگه.
بازگشتها
قول< تنظیمات زوم >
کروم ۸۸+با تنظیمات بزرگنمایی فعلی برگه حل میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
goBack()
chrome.tabs.goBack(
tabId?: number,
callback?: function,
): Promise<void>
اگر صفحهای در دسترس بود، به صفحه قبل برگردید.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که قرار است به عقب برگردد؛ بهطور پیشفرض روی برگهی انتخابشدهی پنجرهی فعلی قرار دارد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
goForward()
chrome.tabs.goForward(
tabId?: number,
callback?: function,
): Promise<void>
اگر صفحهای در دسترس بود، به صفحه بعد بروید.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که قرار است به جلو حرکت کند؛ بهطور پیشفرض روی برگهی انتخابشدهی پنجرهی فعلی قرار دارد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
group()
chrome.tabs.group(
options: object,
callback?: function,
): Promise<number>
یک یا چند تب را به یک گروه مشخص شده اضافه میکند، یا اگر هیچ گروهی مشخص نشده باشد، تبهای داده شده را به یک گروه تازه ایجاد شده اضافه میکند.
پارامترها
- گزینهها
شیء
- ایجاد ویژگیها
شیء اختیاری
پیکربندیهایی برای ایجاد یک گروه. اگر groupId از قبل مشخص شده باشد، نمیتوان از آن استفاده کرد.
- شناسه پنجره
شماره اختیاری
پنجرهی گروه جدید. پیشفرض پنجرهی فعلی است.
- شناسه گروه
شماره اختیاری
شناسهی گروهی که تبها به آن اضافه میشوند. اگر مشخص نشود، یک گروه جدید ایجاد خواهد شد.
- شناسههای برگه
عدد | [عدد، ...عدد[]]
شناسهی برگه یا فهرست شناسههای برگه برای اضافه کردن به گروه مشخصشده.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(groupId: number) => void
- شناسه گروه
شماره
شناسه گروهی که تبها به آن اضافه شدهاند.
بازگشتها
قول<number>
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
highlight()
chrome.tabs.highlight(
highlightInfo: object,
callback?: function,
): Promise<windows.Window>
تبهای داده شده را هایلایت میکند و روی اولین تب از گروه فوکوس میکند. اگر تب مشخص شده در حال حاضر فعال باشد، به نظر میرسد که هیچ کاری انجام نمیدهد.
پارامترها
- اطلاعات برجسته
شیء
- زبانهها
عدد | عدد[]
یک یا چند شاخص تب برای برجسته کردن.
- شناسه پنجره
شماره اختیاری
پنجرهای که شامل تبها میشود.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(window: Window) => void
- پنجره
حاوی جزئیاتی درباره پنجرهای است که تبهای آن هایلایت شدهاند.
بازگشتها
قول < windows.Window >
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
insertCSS()
chrome.tabs.insertCSS(
tabId?: number,
details: InjectDetails,
callback?: function,
): Promise<void>
با scripting.insertCSS در Manifest V3 جایگزین شد.
CSS را به یک صفحه تزریق میکند. استایلهای درج شده با این روش را میتوان با scripting.removeCSS حذف کرد. برای جزئیات بیشتر، به بخش تزریق برنامهنویسیشده در سند اسکریپتهای محتوا مراجعه کنید.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که CSS در آن درج میشود؛ بهطور پیشفرض روی برگهی فعال پنجرهی فعلی قرار دارد.
- جزئیات
جزئیات متن CSS برای درج. یا کد یا ویژگی فایل باید تنظیم شوند، اما هر دو را نمیتوان همزمان تنظیم کرد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
کروم ۸۸+زمانی که تمام CSS درج شده باشد، برطرف میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
move()
chrome.tabs.move(
tabIds: number | number[],
moveProperties: object,
callback?: function,
): Promise<Tab | Tab[]>
یک یا چند تب را به موقعیت جدیدی در پنجره خود یا به یک پنجره جدید منتقل میکند. توجه داشته باشید که تبها فقط میتوانند به پنجرههای معمولی (window.type === "normal") منتقل شوند.
پارامترها
- شناسههای برگه
عدد | عدد[]
شناسهی برگه یا فهرست شناسههای برگههایی که باید جابهجا شوند.
- ویژگیهای حرکت
شیء
- شاخص
شماره
موقعیتی که پنجره به آن منتقل میشود. برای قرار دادن تب در انتهای پنجره
-1استفاده کنید. - شناسه پنجره
شماره اختیاری
پیشفرض روی پنجرهای است که برگه در حال حاضر در آن قرار دارد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(tabs: Tab | Tab[]) => void
بازگشتها
- کروم ۸۸+
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
query()
chrome.tabs.query(
queryInfo: object,
callback?: function,
): Promise<Tab[]>
تمام تبهایی که ویژگیهای مشخصشده را دارند، یا تمام تبها را در صورتی که هیچ ویژگی مشخص نشده باشد، برمیگرداند.
پارامترها
- اطلاعات پرس و جو
شیء
- فعال
بولی اختیاری
اینکه آیا تبها در پنجرههایشان فعال هستند یا خیر.
- قابل شنیدن
بولی اختیاری
کروم ۴۵+اینکه آیا زبانهها قابل شنیدن هستند یا خیر.
- خودکارقابل حذف
بولی اختیاری
کروم ۵۴+اینکه آیا مرورگر میتواند در صورت کمبود منابع، تبها را بهطور خودکار حذف کند یا خیر.
- پنجره فعلی
بولی اختیاری
اینکه آیا تبها در پنجرهی فعلی هستند یا خیر.
- دور انداخته شده
بولی اختیاری
کروم ۵۴+اینکه آیا تبها حذف شدهاند یا خیر. تب حذفشده، تبی است که محتوای آن از حافظه حذف شده است، اما هنوز در نوار تبها قابل مشاهده است. محتوای آن دفعهی بعد که فعال شود، دوباره بارگذاری میشود.
- یخ زده
بولی اختیاری
کروم ۱۳۲+اینکه آیا تبها قفل شدهاند یا خیر. یک تب قفلشده نمیتواند وظایفی از جمله کنترلکنندههای رویداد یا تایمرها را اجرا کند. در نوار تبها قابل مشاهده است و محتوای آن در حافظه بارگذاری میشود. هنگام فعالسازی قفلشده از حالت قفلشده خارج میشود.
- شناسه گروه
شماره اختیاری
کروم ۸۸+شناسه گروهی که تبها در آن قرار دارند، یا
tabGroups.TAB_GROUP_ID_NONEبرای تبهای گروهبندی نشده. - برجسته شده
بولی اختیاری
اینکه آیا تبها هایلایت شدهاند یا خیر.
- شاخص
شماره اختیاری
موقعیت تبها در پنجرههایشان.
- آخرین پنجره متمرکز
بولی اختیاری
اینکه آیا تبها در آخرین پنجرهی فوکوسشده قرار دارند یا خیر.
- خاموش
بولی اختیاری
کروم ۴۵+اینکه آیا زبانهها بیصدا هستند یا خیر.
- سنجاق شده
بولی اختیاری
اینکه آیا تبها پین شدهاند یا خیر.
- splitViewId
شماره اختیاری
کروم ۱۴۰+شناسهی نمای تقسیمشدهای که تبها در آن قرار دارند، یا
tabs.SPLIT_VIEW_ID_NONEبرای تبهایی که در نمای تقسیمشده نیستند. - وضعیت
وضعیت برگه ( اختیاری)
وضعیت بارگذاری تب.
- عنوان
رشته اختیاری
عناوین صفحات را با یک الگو مطابقت دهید. اگر افزونه مجوز
"tabs"یا مجوزهای میزبان برای صفحه را نداشته باشد، این ویژگی نادیده گرفته میشود. - آدرس اینترنتی
رشته | رشته[] اختیاری
تبها را با یک یا چند الگوی URL مطابقت دهید. شناسههای قطعه مطابقت ندارند. اگر افزونه مجوز
"tabs"یا مجوزهای میزبان برای صفحه را نداشته باشد، این ویژگی نادیده گرفته میشود. - شناسه پنجره
شماره اختیاری
شناسه پنجره والد، یا
windows.WINDOW_ID_CURRENTبرای پنجره فعلی . - نوع پنجره
نوع پنجره اختیاری
نوع پنجرهای که تبها در آن قرار دارند.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(result: Tab[]) => void
- نتیجه
تب []
بازگشتها
قول بده< تب []>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
reload()
chrome.tabs.reload(
tabId?: number,
reloadProperties?: object,
callback?: function,
): Promise<void>
یک برگه را دوباره بارگذاری کنید.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که قرار است بارگذاری مجدد شود؛ بهطور پیشفرض، برگهی انتخابشدهی پنجرهی فعلی است.
- بارگذاری مجدد ویژگیها
شیء اختیاری
- بایپسکش
بولی اختیاری
اینکه آیا از ذخیرهسازی محلی صرفنظر شود یا خیر. مقدار پیشفرض
falseاست.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
remove()
chrome.tabs.remove(
tabIds: number | number[],
callback?: function,
): Promise<void>
یک یا چند تب را میبندد.
پارامترها
- شناسههای برگه
عدد | عدد[]
شناسهی برگه یا فهرست شناسههای برگههایی که باید بسته شوند.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
removeCSS()
chrome.tabs.removeCSS(
tabId?: number,
details: DeleteInjectionDetails,
callback?: function,
): Promise<void>
با scripting.removeCSS در Manifest V3 جایگزین شد.
CSS ای را که قبلاً با فراخوانی scripting.insertCSS تزریق شده است، از صفحه حذف میکند.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که CSS از آن حذف میشود؛ بهطور پیشفرض روی برگهی فعال پنجرهی فعلی قرار دارد.
- جزئیات
جزئیات متن CSS که باید حذف شود. یا کد یا ویژگی فایل باید تنظیم شوند، اما هر دو را نمیتوان همزمان تنظیم کرد.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
کروم ۸۸+زمانی که تمام CSS حذف شده باشد، برطرف میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
sendMessage()
chrome.tabs.sendMessage(
tabId: number,
message: any,
options?: object,
callback?: function,
): Promise<any>
یک پیام واحد را به اسکریپت(های) محتوا در تب مشخص شده ارسال میکند. رویداد runtime.onMessage در هر اسکریپت محتوا که در تب مشخص شده برای افزونه فعلی اجرا میشود، اجرا میشود.
پارامترها
- شناسه برگه
شماره
- پیام
هر
پیامی که باید ارسال شود. این پیام باید یک شیء با قابلیت پشتیبانی از JSON باشد.
- گزینهها
شیء اختیاری
- تماس برگشتی
تابع اختیاری
کروم ۹۹+پارامتر
callbackبه شکل زیر است:(response: any) => void
- پاسخ
هر
شیء پاسخ JSON که توسط مدیریتکنندهی پیام ارسال میشود.
بازگشتها
قول بده<any>
کروم ۹۹+وعدهای که با پاسخ از اسکریپت محتوا حل میشود. اگر هنگام اتصال به برگه مشخص شده خطایی رخ دهد، وعده رد میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
sendRequest()
chrome.tabs.sendRequest(
tabId: number,
request: any,
callback?: function,
): Promise<any>
لطفا از runtime.sendMessage استفاده کنید.
یک درخواست واحد به اسکریپت(های) محتوا در تب مشخص شده ارسال میکند، به همراه یک فراخوانی اختیاری که هنگام ارسال پاسخ اجرا میشود. رویداد extension.onRequest در هر اسکریپت محتوا که در تب مشخص شده برای افزونه فعلی اجرا میشود، اجرا میشود.
پارامترها
- شناسه برگه
شماره
- درخواست
هر
- تماس برگشتی
تابع اختیاری
کروم ۹۹+پارامتر
callbackبه شکل زیر است:(response: any) => void
- پاسخ
هر
شیء پاسخ JSON ارسال شده توسط کنترلکنندهی درخواست. اگر هنگام اتصال به تب مشخص شده خطایی رخ دهد، promise رد خواهد شد.
بازگشتها
قول بده<any>
کروم ۹۹+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
setZoom()
chrome.tabs.setZoom(
tabId?: number,
zoomFactor: number,
callback?: function,
): Promise<void>
یک تب مشخص شده را بزرگنمایی میکند.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که قرار است بزرگنمایی شود؛ بهطور پیشفرض روی برگهی فعال پنجرهی فعلی قرار دارد.
- زوم فاکتور
شماره
ضریب بزرگنمایی جدید. مقدار
0، ضریب بزرگنمایی پیشفرض فعلی تب را تنظیم میکند. مقادیر بزرگتر از0یک ضریب بزرگنمایی (احتمالاً غیر پیشفرض) برای تب مشخص میکنند. - تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
کروم ۸۸+پس از تغییر ضریب بزرگنمایی، حل میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
setZoomSettings()
chrome.tabs.setZoomSettings(
tabId?: number,
zoomSettings: ZoomSettings,
callback?: function,
): Promise<void>
تنظیمات بزرگنمایی را برای یک برگه مشخص شده تنظیم میکند، که نحوه مدیریت تغییرات بزرگنمایی را تعریف میکند. این تنظیمات پس از پیمایش برگه به مقادیر پیشفرض بازنشانی میشوند.
پارامترها
- شناسه برگه
شماره اختیاری
شناسهی برگهای که تنظیمات بزرگنمایی برای آن تغییر میکند؛ بهطور پیشفرض روی برگهی فعال پنجرهی فعلی قرار دارد.
- تنظیمات زوم
تعریف میکند که تغییرات بزرگنمایی چگونه و در چه محدودهای مدیریت شوند.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
کروم ۸۸+پس از تغییر تنظیمات زوم، مشکل برطرف میشود.
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
ungroup()
chrome.tabs.ungroup(
tabIds: number | [number, ...number[]],
callback?: function,
): Promise<void>
یک یا چند تب را از گروههای مربوطه حذف میکند. اگر هر گروهی خالی شود، حذف میشود.
پارامترها
- شناسههای برگه
عدد | [عدد، ...عدد[]]
شناسهی برگه یا فهرست شناسههای برگه برای حذف از گروههای مربوطه.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:() => void
بازگشتها
قول<void>
Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
update()
chrome.tabs.update(
tabId?: number,
updateProperties: object,
callback?: function,
): Promise<Tab | undefined>
ویژگیهای یک تب را تغییر میدهد. ویژگیهایی که در updateProperties مشخص نشدهاند، تغییر نمیکنند.
پارامترها
- شناسه برگه
شماره اختیاری
به طور پیشفرض روی برگه انتخاب شده از پنجره فعلی قرار میگیرد.
- بهروزرسانیها
شیء
- فعال
بولی اختیاری
اینکه آیا تب باید فعال باشد یا خیر. تاثیری بر اینکه پنجره در حالت فوکوس باشد یا خیر ندارد (به
windows.updateمراجعه کنید). - خودکارقابل حذف
بولی اختیاری
کروم ۵۴+اینکه آیا مرورگر در صورت کمبود منابع، تب را بهطور خودکار حذف کند یا خیر.
- برجسته شده
بولی اختیاری
تب را از انتخاب فعلی اضافه یا حذف میکند.
- خاموش
بولی اختیاری
کروم ۴۵+اینکه آیا تب باید بیصدا شود یا خیر.
- تب آی دی بازکننده
شماره اختیاری
شناسهی برگهای که این برگه را باز کرده است. در صورت مشخص شدن، برگهی بازکننده باید در همان پنجرهای باشد که این برگه در آن قرار دارد.
- سنجاق شده
بولی اختیاری
اینکه آیا تب باید پین شود یا خیر.
- انتخاب شده
بولی اختیاری
منسوخ شدهلطفا از هایلایت شده استفاده کنید.
اینکه آیا برگه باید انتخاب شود یا خیر.
- آدرس اینترنتی
رشته اختیاری
یک URL برای پیمایش تب. URL های جاوا اسکریپت پشتیبانی نمیشوند؛ به جای آن
scripting.executeScriptاستفاده کنید.
- تماس برگشتی
تابع اختیاری
پارامتر
callbackبه شکل زیر است:(tab?: Tab) => void
بازگشتها
قول< تب | تعریف نشده>
کروم ۸۸+Promiseها فقط برای Manifest V3 و نسخههای بعدی پشتیبانی میشوند، سایر پلتفرمها باید از callbackها استفاده کنند.
رویدادها
onActivated
chrome.tabs.onActivated.addListener(
callback: function,
)
زمانی اتفاق میافتد که تب فعال در یک پنجره تغییر کند. توجه داشته باشید که ممکن است URL تب در زمان اجرای این رویداد تنظیم نشده باشد، اما میتوانید به رویدادهای onUpdated گوش دهید تا هنگام تنظیم URL مطلع شوید.
پارامترها
- تماس برگشتی
تابع
پارامتر
callbackبه شکل زیر است:(activeInfo: object) => void
- اطلاعات فعال
شیء
- شناسه برگه
شماره
شناسهی برگهای که فعال شده است.
- شناسه پنجره
شماره
شناسهی پنجرهای که تب فعال درون آن تغییر کرده است.
onActiveChanged
chrome.tabs.onActiveChanged.addListener(
callback: function,
)
لطفاً از tabs.onActivated استفاده کنید.
زمانی اتفاق میافتد که تب انتخابشده در یک پنجره تغییر کند. توجه داشته باشید که ممکن است URL تب در زمان اجرای این رویداد تنظیم نشده باشد، اما میتوانید به رویدادهای tabs.onUpdated گوش دهید تا هنگام تنظیم URL مطلع شوید.
پارامترها
- تماس برگشتی
تابع
پارامتر
callbackبه شکل زیر است:(tabId: number, selectInfo: object) => void
- شناسه برگه
شماره
- انتخاباطلاعات
شیء
- شناسه پنجره
شماره
شناسهی پنجرهای که تب انتخابشده درون آن تغییر کرده است.
onAttached
chrome.tabs.onAttached.addListener(
callback: function,
)
زمانی اجرا میشود که یک تب به یک پنجره متصل شده باشد؛ برای مثال، به دلیل جابجایی بین پنجرهها.
پارامترها
- تماس برگشتی
تابع
پارامتر
callbackبه شکل زیر است:(tabId: number, attachInfo: object) => void
- شناسه برگه
شماره
- اطلاعات پیوست
شیء
- موقعیت جدید
شماره
- شناسه پنجره جدید
شماره
onCreated
chrome.tabs.onCreated.addListener(
callback: function,
)
هنگام ایجاد یک تب، فعال میشود. توجه داشته باشید که ممکن است URL تب و عضویت در گروه تب در زمان فعال شدن این رویداد تنظیم نشده باشند، اما میتوانید به رویدادهای onUpdated گوش دهید تا هنگام تنظیم URL یا اضافه شدن تب به یک گروه تب، مطلع شوید.
onDetached
chrome.tabs.onDetached.addListener(
callback: function,
)
زمانی اجرا میشود که یک تب از یک پنجره جدا شود؛ برای مثال، به دلیل اینکه بین پنجرهها جابجا شده است.
پارامترها
- تماس برگشتی
تابع
پارامتر
callbackبه شکل زیر است:(tabId: number, detachInfo: object) => void
- شناسه برگه
شماره
- اطلاعات را جدا کنید
شیء
- موقعیت قدیمی
شماره
- شناسه پنجره قدیمی
شماره
onHighlightChanged
chrome.tabs.onHighlightChanged.addListener(
callback: function,
)
Please use tabs.onHighlighted .
Fired when the highlighted or selected tabs in a window changes.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(selectInfo: object) => void
- selectInfo
شیء
- tabIds
number[]
All highlighted tabs in the window.
- windowId
شماره
The window whose tabs changed.
onHighlighted
chrome.tabs.onHighlighted.addListener(
callback: function,
)
Fired when the highlighted or selected tabs in a window changes.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(highlightInfo: object) => void
- highlightInfo
شیء
- tabIds
number[]
All highlighted tabs in the window.
- windowId
شماره
The window whose tabs changed.
onMoved
chrome.tabs.onMoved.addListener(
callback: function,
)
Fired when a tab is moved within a window. Only one move event is fired, representing the tab the user directly moved. Move events are not fired for the other tabs that must move in response to the manually-moved tab. This event is not fired when a tab is moved between windows; for details, see tabs.onDetached .
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, moveInfo: object) => void
- tabId
شماره
- moveInfo
شیء
- fromIndex
شماره
- toIndex
شماره
- windowId
شماره
onRemoved
chrome.tabs.onRemoved.addListener(
callback: function,
)
Fired when a tab is closed.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, removeInfo: object) => void
- tabId
شماره
- removeInfo
شیء
- isWindowClosing
بولی
True when the tab was closed because its parent window was closed.
- windowId
شماره
The window whose tab is closed.
onReplaced
chrome.tabs.onReplaced.addListener(
callback: function,
)
Fired when a tab is replaced with another tab due to prerendering or instant.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(addedTabId: number, removedTabId: number) => void
- addedTabId
شماره
- removedTabId
شماره
onSelectionChanged
chrome.tabs.onSelectionChanged.addListener(
callback: function,
)
Please use tabs.onActivated .
Fires when the selected tab in a window changes.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, selectInfo: object) => void
- tabId
شماره
- selectInfo
شیء
- windowId
شماره
The ID of the window the selected tab changed inside of.
onUpdated
chrome.tabs.onUpdated.addListener(
callback: function,
)
Fired when a tab is updated.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, changeInfo: object, tab: Tab) => void
- tabId
شماره
- changeInfo
شیء
- قابل شنیدن
بولی اختیاری
Chrome 45+The tab's new audible state.
- autoDiscardable
بولی اختیاری
Chrome 54+The tab's new auto-discardable state.
- دور انداخته شده
بولی اختیاری
Chrome 54+The tab's new discarded state.
- favIconUrl
string optional
The tab's new favicon URL.
- یخ زده
بولی اختیاری
Chrome 132+The tab's new frozen state.
- groupId
number optional
Chrome 88+The tab's new group.
- mutedInfo
MutedInfo optional
Chrome 46+The tab's new muted state and the reason for the change.
- سنجاق شده
بولی اختیاری
The tab's new pinned state.
- splitViewId
number optional
Chrome 140+The tab's new Split View.
- وضعیت
TabStatus optional
The tab's loading status.
- عنوان
string optional
Chrome 48+The tab's new title.
- آدرس اینترنتی
string optional
The tab's URL if it has changed.
- تب
onZoomChange
chrome.tabs.onZoomChange.addListener(
callback: function,
)
Fired when a tab is zoomed.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(ZoomChangeInfo: object) => void
- ZoomChangeInfo
شیء
- newZoomFactor
شماره
- oldZoomFactor
شماره
- tabId
شماره
- zoomSettings
توضیحات
Use the chrome.tabs API to interact with the browser's tab system. You can use this API to create, modify, and rearrange tabs in the browser.
نمای کلی
The Tabs API not only offers features for manipulating and managing tabs, but can also detect the language of the tab, take a screenshot , and communicate with a tab's content scripts.
مجوزها
Most features do not require any permissions to use. For example: creating a new tab, reloading a tab, navigating to another URL, etc.
There are three permissions developers should be aware of when working with the Tabs API.
- The "tabs" permission
- This permission does not give access to the
chrome.tabsnamespace. Instead, it grants an extension the ability to calltabs.query()against four sensitive properties ontabs.Tabinstances:url,pendingUrl,title, andfavIconUrl. - Host permissions
- Host permissions allow an extension to read and query a matching tab's four sensitive
tabs.Tabproperties. They can also interact directly with the matching tabs using methods such astabs.captureVisibleTab(),tabs.executeScript(),tabs.insertCSS(), andtabs.removeCSS(). - The "activeTab" permission
-
activeTabgrants an extension temporary host permission for the current tab in response to a user invocation. Unlike host permissions,activeTabdoes not trigger any warnings.
مانیفست
The following are examples of how to declare each permission in the manifest :
{
"name": "My extension",
...
"permissions": [
"tabs"
],
...
}
{
"name": "My extension",
...
"host_permissions": [
"http://*/*",
"https://*/*"
],
...
}
{
"name": "My extension",
...
"permissions": [
"activeTab"
],
...
}
موارد استفاده
The following sections demonstrate some common use cases.
Opening an extension page in a new tab
A common pattern for extensions is to open an onboarding page in a new tab when the extension is installed. The following example shows how to do this.
background.js:
chrome.runtime.onInstalled.addListener(({reason}) => {
if (reason === 'install') {
chrome.tabs.create({
url: "onboarding.html"
});
}
});
Get the current tab
This example demonstrates how an extension's service worker can retrieve the active tab from the currently-focused window (or most recently-focused window, if no Chrome windows are focused). This can usually be thought of as the user's current tab.
async function getCurrentTab() {
let queryOptions = { active: true, lastFocusedWindow: true };
// `tab` will either be a `tabs.Tab` instance or `undefined`.
let [tab] = await chrome.tabs.query(queryOptions);
return tab;
}
function getCurrentTab(callback) {
let queryOptions = { active: true, lastFocusedWindow: true };
chrome.tabs.query(queryOptions, ([tab]) => {
if (chrome.runtime.lastError)
console.error(chrome.runtime.lastError);
// `tab` will either be a `tabs.Tab` instance or `undefined`.
callback(tab);
});
}
Mute the specified tab
This example shows how an extension can toggle the muted state for a given tab.
async function toggleMuteState(tabId) {
const tab = await chrome.tabs.get(tabId);
const muted = !tab.mutedInfo.muted;
await chrome.tabs.update(tabId, {muted});
console.log(`Tab ${tab.id} is ${muted ? "muted" : "unmuted"}`);
}
function toggleMuteState(tabId) {
chrome.tabs.get(tabId, async (tab) => {
let muted = !tab.mutedInfo.muted;
await chrome.tabs.update(tabId, { muted });
console.log(`Tab ${tab.id} is ${ muted ? "muted" : "unmuted" }`);
});
}
Move the current tab to the first position when clicked
This example shows how to move a tab while a drag may or may not be in progress. While this example uses chrome.tabs.move , you can use the same waiting pattern for other calls that modify tabs while a drag is in progress.
chrome.tabs.onActivated.addListener(moveToFirstPosition);
async function moveToFirstPosition(activeInfo) {
try {
await chrome.tabs.move(activeInfo.tabId, {index: 0});
console.log("Success.");
} catch (error) {
if (error == "Error: Tabs cannot be edited right now (user may be dragging a tab).") {
setTimeout(() => moveToFirstPosition(activeInfo), 50);
} else {
console.error(error);
}
}
}
chrome.tabs.onActivated.addListener(moveToFirstPositionMV2);
function moveToFirstPositionMV2(activeInfo) {
chrome.tabs.move(activeInfo.tabId, { index: 0 }, () => {
if (chrome.runtime.lastError) {
const error = chrome.runtime.lastError;
if (error == "Error: Tabs cannot be edited right now (user may be dragging a tab).") {
setTimeout(() => moveToFirstPositionMV2(activeInfo), 50);
} else {
console.error(error);
}
} else {
console.log("Success.");
}
});
}
Pass a message to a selected tab's content script
This example demonstrates how an extension's service worker can communicate with content scripts in specific browser tabs using tabs.sendMessage() .
function sendMessageToActiveTab(message) {
const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
const response = await chrome.tabs.sendMessage(tab.id, message);
// TODO: Do something with the response.
}
Extension examples
For more Tabs API extensions demos, explore any of the following:
انواع
MutedInfo
The tab's muted state and the reason for the last state change.
خواص
- extensionId
string optional
The ID of the extension that changed the muted state. Not set if an extension was not the reason the muted state last changed.
- خاموش
بولی
Whether the tab is muted (prevented from playing sound). The tab may be muted even if it has not played or is not currently playing sound. Equivalent to whether the 'muted' audio indicator is showing.
- دلیل
MutedInfoReason optional
The reason the tab was muted or unmuted. Not set if the tab's mute state has never been changed.
MutedInfoReason
An event that caused a muted state change.
شمارشی
"user" "capture" "extension"
A user input action set the muted state.
Tab capture was started, forcing a muted state change.
An extension, identified by the extensionId field, set the muted state.
Tab
خواص
- فعال
بولی
Whether the tab is active in its window. Does not necessarily mean the window is focused.
- قابل شنیدن
بولی اختیاری
Chrome 45+Whether the tab has produced sound over the past couple of seconds (but it might not be heard if also muted). Equivalent to whether the 'speaker audio' indicator is showing.
- autoDiscardable
بولی
Chrome 54+Whether the tab can be discarded automatically by the browser when resources are low.
- دور انداخته شده
بولی
Chrome 54+Whether the tab is discarded. A discarded tab is one whose content has been unloaded from memory, but is still visible in the tab strip. Its content is reloaded the next time it is activated.
- favIconUrl
string optional
The URL of the tab's favicon. This property is only present if the extension has the
"tabs"permission or has host permissions for the page. It may also be an empty string if the tab is loading. - یخ زده
بولی
Chrome 132+Whether the tab is frozen. A frozen tab cannot execute tasks, including event handlers or timers. It is visible in the tab strip and its content is loaded in memory. It is unfrozen on activation.
- groupId
شماره
Chrome 88+The ID of the group that the tab belongs to.
- ارتفاع
number optional
The height of the tab in pixels.
- برجسته شده
بولی
Whether the tab is highlighted.
- شناسه
number optional
The ID of the tab. Tab IDs are unique within a browser session. Under some circumstances a tab may not be assigned an ID; for example, when querying foreign tabs using the
sessionsAPI, in which case a session ID may be present. Tab ID can also be set tochrome.tabs.TAB_ID_NONEfor apps and devtools windows. - ناشناس
بولی
Whether the tab is in an incognito window.
- شاخص
شماره
The zero-based index of the tab within its window.
- lastAccessed
شماره
Chrome 121+The last time the tab became active in its window as the number of milliseconds since epoch.
- mutedInfo
MutedInfo optional
Chrome 46+The tab's muted state and the reason for the last state change.
- openerTabId
number optional
The ID of the tab that opened this tab, if any. This property is only present if the opener tab still exists.
- pendingUrl
string optional
Chrome 79+The URL the tab is navigating to, before it has committed. This property is only present if the extension has the
"tabs"permission or has host permissions for the page and there is a pending navigation. - سنجاق شده
بولی
Whether the tab is pinned.
- انتخاب شده
بولی
منسوخ شدهPlease use
tabs.Tab.highlighted.Whether the tab is selected.
- sessionId
string optional
The session ID used to uniquely identify a tab obtained from the
sessionsAPI. - splitViewId
number optional
Chrome 145+The ID of the Split View that the tab belongs to.
- وضعیت
TabStatus optional
The tab's loading status.
- عنوان
string optional
The title of the tab. This property is only present if the extension has the
"tabs"permission or has host permissions for the page. - آدرس اینترنتی
string optional
The last committed URL of the main frame of the tab. This property is only present if the extension has the
"tabs"permission or has host permissions for the page. May be an empty string if the tab has not yet committed. See alsoTab.pendingUrl. - عرض
number optional
The width of the tab in pixels.
- windowId
شماره
The ID of the window that contains the tab.
TabStatus
The tab's loading status.
شمارشی
"unloaded" "loading" "complete"
WindowType
The type of window.
شمارشی
"normal" "popup" "panel" "app" "devtools"
ZoomSettings
Defines how zoom changes in a tab are handled and at what scope.
خواص
- defaultZoomFactor
number optional
Chrome 43+Used to return the default zoom level for the current tab in calls to tabs.getZoomSettings.
- حالت
ZoomSettingsMode optional
Defines how zoom changes are handled, ie, which entity is responsible for the actual scaling of the page; defaults to
automatic. - محدوده
ZoomSettingsScope optional
Defines whether zoom changes persist for the page's origin, or only take effect in this tab; defaults to
per-originwhen inautomaticmode, andper-tabotherwise.
ZoomSettingsMode
Defines how zoom changes are handled, ie, which entity is responsible for the actual scaling of the page; defaults to automatic .
شمارشی
"automatic" "manual" "disabled"
Zoom changes are handled automatically by the browser.
Overrides the automatic handling of zoom changes. The onZoomChange event will still be dispatched, and it is the extension's responsibility to listen for this event and manually scale the page. This mode does not support per-origin zooming, and thus ignores the scope zoom setting and assumes per-tab .
Disables all zooming in the tab. The tab reverts to the default zoom level, and all attempted zoom changes are ignored.
ZoomSettingsScope
Defines whether zoom changes persist for the page's origin, or only take effect in this tab; defaults to per-origin when in automatic mode, and per-tab otherwise.
شمارشی
"per-origin" "per-tab"
Zoom changes persist in the zoomed page's origin, ie, all other tabs navigated to that same origin are zoomed as well. Moreover, per-origin zoom changes are saved with the origin, meaning that when navigating to other pages in the same origin, they are all zoomed to the same zoom factor. The per-origin scope is only available in the automatic mode.
Zoom changes only take effect in this tab, and zoom changes in other tabs do not affect the zooming of this tab. Also, per-tab zoom changes are reset on navigation; navigating a tab always loads pages with their per-origin zoom factors.
خواص
MAX_CAPTURE_VISIBLE_TAB_CALLS_PER_SECOND
The maximum number of times that captureVisibleTab can be called per second. captureVisibleTab is expensive and should not be called too often.
ارزش
۲
SPLIT_VIEW_ID_NONE
An ID that represents the absence of a split tab.
ارزش
-1
TAB_ID_NONE
An ID that represents the absence of a browser tab.
ارزش
-1
TAB_INDEX_NONE
An index that represents the absence of a tab index in a tab_strip.
ارزش
-1
روشها
captureVisibleTab()
chrome.tabs.captureVisibleTab(
windowId?: number,
options?: ImageDetails,
callback?: function,
): Promise<string>
Captures the visible area of the currently active tab in the specified window. In order to call this method, the extension must have either the <all_urls> permission or the activeTab permission. In addition to sites that extensions can normally access, this method allows extensions to capture sensitive sites that are otherwise restricted, including chrome:-scheme pages, other extensions' pages, and data: URLs. These sensitive sites can only be captured with the activeTab permission. File URLs may be captured only if the extension has been granted file access.
پارامترها
- windowId
number optional
The target window. Defaults to the current window .
- گزینهها
ImageDetails optional
- تماس برگشتی
function optional
The
callbackparameter looks like:(dataUrl: string) => void
- dataUrl
رشته
A data URL that encodes an image of the visible area of the captured tab. May be assigned to the 'src' property of an HTML
imgelement for display.
بازگشتها
Promise<string>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
connect()
chrome.tabs.connect(
tabId: number,
connectInfo?: object,
): runtime.Port
Connects to the content script(s) in the specified tab. The runtime.onConnect event is fired in each content script running in the specified tab for the current extension. For more details, see Content Script Messaging .
پارامترها
- tabId
شماره
- connectInfo
object optional
- documentId
string optional
Chrome 106+Open a port to a specific document identified by
documentIdinstead of all frames in the tab. - frameId
number optional
Open a port to a specific frame identified by
frameIdinstead of all frames in the tab. - نام
string optional
Is passed into onConnect for content scripts that are listening for the connection event.
بازگشتها
A port that can be used to communicate with the content scripts running in the specified tab. The port's
runtime.Portevent is fired if the tab closes or does not exist.
create()
chrome.tabs.create(
createProperties: object,
callback?: function,
): Promise<Tab>
Creates a new tab.
پارامترها
- createProperties
شیء
- فعال
بولی اختیاری
Whether the tab should become the active tab in the window. Does not affect whether the window is focused (see
windows.update). Defaults totrue. - شاخص
number optional
The position the tab should take in the window. The provided value is clamped to between zero and the number of tabs in the window.
- openerTabId
number optional
The ID of the tab that opened this tab. If specified, the opener tab must be in the same window as the newly created tab.
- سنجاق شده
بولی اختیاری
Whether the tab should be pinned. Defaults to
false - انتخاب شده
بولی اختیاری
منسوخ شدهPlease use active .
Whether the tab should become the selected tab in the window. Defaults to
true - آدرس اینترنتی
string optional
The URL to initially navigate the tab to. Fully-qualified URLs must include a scheme (ie, 'http://www.google.com', not 'www.google.com'). Relative URLs are relative to the current page within the extension. Defaults to the New Tab Page.
- windowId
number optional
The window in which to create the new tab. Defaults to the current window .
- تماس برگشتی
function optional
The
callbackparameter looks like:(tab: Tab) => void
- تب
The created tab.
بازگشتها
Promise< Tab >
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
detectLanguage()
chrome.tabs.detectLanguage(
tabId?: number,
callback?: function,
): Promise<string>
Detects the primary language of the content in a tab.
پارامترها
- tabId
number optional
Defaults to the active tab of the current window .
- تماس برگشتی
function optional
The
callbackparameter looks like:(language: string) => void
- زبان
رشته
An ISO language code such as
enorfr. For a complete list of languages supported by this method, see kLanguageInfoTable . The second to fourth columns are checked and the first non-NULL value is returned, except for Simplified Chinese for whichzh-CNis returned. For an unknown/undefined language,undis returned.
بازگشتها
Promise<string>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
discard()
chrome.tabs.discard(
tabId?: number,
callback?: function,
): Promise<Tab | undefined>
Discards a tab from memory. Discarded tabs are still visible on the tab strip and are reloaded when activated.
پارامترها
- tabId
number optional
The ID of the tab to be discarded. If specified, the tab is discarded unless it is active or already discarded. If omitted, the browser discards the least important tab. This can fail if no discardable tabs exist.
- تماس برگشتی
function optional
The
callbackparameter looks like:(tab?: Tab) => void
- تب
Tab optional
The discarded tab, if it was successfully discarded; undefined otherwise.
بازگشتها
Promise< Tab | undefined>
Chrome 88+Resolves after the operation is completed.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
duplicate()
chrome.tabs.duplicate(
tabId: number,
callback?: function,
): Promise<Tab | undefined>
Duplicates a tab.
پارامترها
- tabId
شماره
The ID of the tab to duplicate.
- تماس برگشتی
function optional
The
callbackparameter looks like:(tab?: Tab) => void
بازگشتها
Promise< Tab | undefined>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
executeScript()
chrome.tabs.executeScript(
tabId?: number,
details: InjectDetails,
callback?: function,
): Promise<any[] | undefined>
Replaced by scripting.executeScript in Manifest V3.
Injects JavaScript code into a page. For details, see the programmatic injection section of the content scripts doc.
پارامترها
- tabId
number optional
The ID of the tab in which to run the script; defaults to the active tab of the current window.
- جزئیات
Details of the script to run. Either the code or the file property must be set, but both may not be set at the same time.
- تماس برگشتی
function optional
The
callbackparameter looks like:(result?: any[]) => void
- نتیجه
any[] optional
The result of the script in every injected frame.
بازگشتها
Promise<any[] | undefined>
Chrome 88+Resolves after all the JavaScript has been executed.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
get()
chrome.tabs.get(
tabId: number,
callback?: function,
): Promise<Tab>
Retrieves details about the specified tab.
پارامترها
- tabId
شماره
- تماس برگشتی
function optional
The
callbackparameter looks like:(tab: Tab) => void
- تب
بازگشتها
Promise< Tab >
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
getAllInWindow()
chrome.tabs.getAllInWindow(
windowId?: number,
callback?: function,
): Promise<Tab[]>
Please use tabs.query {windowId: windowId} .
Gets details about all tabs in the specified window.
پارامترها
- windowId
number optional
Defaults to the current window .
- تماس برگشتی
function optional
The
callbackparameter looks like:(tabs: Tab[]) => void
- زبانهها
Tab []
بازگشتها
Promise< Tab []>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
getCurrent()
chrome.tabs.getCurrent(
callback?: function,
): Promise<Tab | undefined>
Gets the tab that this script call is being made from. Returns undefined if called from a non-tab context (for example, a background page or popup view).
پارامترها
بازگشتها
Promise< Tab | undefined>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
getSelected()
chrome.tabs.getSelected(
windowId?: number,
callback?: function,
): Promise<Tab>
Please use tabs.query {active: true} .
Gets the tab that is selected in the specified window.
پارامترها
- windowId
number optional
Defaults to the current window .
- تماس برگشتی
function optional
The
callbackparameter looks like:(tab: Tab) => void
- تب
بازگشتها
Promise< Tab >
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
getZoom()
chrome.tabs.getZoom(
tabId?: number,
callback?: function,
): Promise<number>
Gets the current zoom factor of a specified tab.
پارامترها
- tabId
number optional
The ID of the tab to get the current zoom factor from; defaults to the active tab of the current window.
- تماس برگشتی
function optional
The
callbackparameter looks like:(zoomFactor: number) => void
- zoomFactor
شماره
The tab's current zoom factor.
بازگشتها
Promise<number>
Chrome 88+Resolves with the tab's current zoom factor after it has been fetched.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
getZoomSettings()
chrome.tabs.getZoomSettings(
tabId?: number,
callback?: function,
): Promise<ZoomSettings>
Gets the current zoom settings of a specified tab.
پارامترها
- tabId
number optional
The ID of the tab to get the current zoom settings from; defaults to the active tab of the current window.
- تماس برگشتی
function optional
The
callbackparameter looks like:(zoomSettings: ZoomSettings) => void
- zoomSettings
The tab's current zoom settings.
بازگشتها
Promise< ZoomSettings >
Chrome 88+Resolves with the tab's current zoom settings.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
goBack()
chrome.tabs.goBack(
tabId?: number,
callback?: function,
): Promise<void>
Go back to the previous page, if one is available.
پارامترها
- tabId
number optional
The ID of the tab to navigate back; defaults to the selected tab of the current window.
- تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
goForward()
chrome.tabs.goForward(
tabId?: number,
callback?: function,
): Promise<void>
Go foward to the next page, if one is available.
پارامترها
- tabId
number optional
The ID of the tab to navigate forward; defaults to the selected tab of the current window.
- تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
group()
chrome.tabs.group(
options: object,
callback?: function,
): Promise<number>
Adds one or more tabs to a specified group, or if no group is specified, adds the given tabs to a newly created group.
پارامترها
- گزینهها
شیء
- createProperties
object optional
Configurations for creating a group. Cannot be used if groupId is already specified.
- windowId
number optional
The window of the new group. Defaults to the current window.
- groupId
number optional
The ID of the group to add the tabs to. If not specified, a new group will be created.
- tabIds
number | [number, ...number[]]
The tab ID or list of tab IDs to add to the specified group.
- تماس برگشتی
function optional
The
callbackparameter looks like:(groupId: number) => void
- groupId
شماره
The ID of the group that the tabs were added to.
بازگشتها
Promise<number>
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
highlight()
chrome.tabs.highlight(
highlightInfo: object,
callback?: function,
): Promise<windows.Window>
Highlights the given tabs and focuses on the first of group. Will appear to do nothing if the specified tab is currently active.
پارامترها
- highlightInfo
شیء
- زبانهها
number | number[]
One or more tab indices to highlight.
- windowId
number optional
The window that contains the tabs.
- تماس برگشتی
function optional
The
callbackparameter looks like:(window: Window) => void
- پنجره
Contains details about the window whose tabs were highlighted.
بازگشتها
Promise< windows.Window >
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
insertCSS()
chrome.tabs.insertCSS(
tabId?: number,
details: InjectDetails,
callback?: function,
): Promise<void>
Replaced by scripting.insertCSS in Manifest V3.
Injects CSS into a page. Styles inserted with this method can be removed with scripting.removeCSS . For details, see the programmatic injection section of the content scripts doc.
پارامترها
- tabId
number optional
The ID of the tab in which to insert the CSS; defaults to the active tab of the current window.
- جزئیات
Details of the CSS text to insert. Either the code or the file property must be set, but both may not be set at the same time.
- تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Chrome 88+Resolves when all the CSS has been inserted.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
move()
chrome.tabs.move(
tabIds: number | number[],
moveProperties: object,
callback?: function,
): Promise<Tab | Tab[]>
Moves one or more tabs to a new position within its window, or to a new window. Note that tabs can only be moved to and from normal (window.type === "normal") windows.
پارامترها
- tabIds
number | number[]
The tab ID or list of tab IDs to move.
- moveProperties
شیء
- شاخص
شماره
The position to move the window to. Use
-1to place the tab at the end of the window. - windowId
number optional
Defaults to the window the tab is currently in.
- تماس برگشتی
function optional
The
callbackparameter looks like:(tabs: Tab | Tab[]) => void
بازگشتها
- Chrome 88+
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
query()
chrome.tabs.query(
queryInfo: object,
callback?: function,
): Promise<Tab[]>
Gets all tabs that have the specified properties, or all tabs if no properties are specified.
پارامترها
- queryInfo
شیء
- فعال
بولی اختیاری
Whether the tabs are active in their windows.
- قابل شنیدن
بولی اختیاری
Chrome 45+Whether the tabs are audible.
- autoDiscardable
بولی اختیاری
Chrome 54+Whether the tabs can be discarded automatically by the browser when resources are low.
- currentWindow
بولی اختیاری
Whether the tabs are in the current window .
- دور انداخته شده
بولی اختیاری
Chrome 54+Whether the tabs are discarded. A discarded tab is one whose content has been unloaded from memory, but is still visible in the tab strip. Its content is reloaded the next time it is activated.
- یخ زده
بولی اختیاری
Chrome 132+Whether the tabs are frozen. A frozen tab cannot execute tasks, including event handlers or timers. It is visible in the tab strip and its content is loaded in memory. It is unfrozen on activation.
- groupId
number optional
Chrome 88+The ID of the group that the tabs are in, or
tabGroups.TAB_GROUP_ID_NONEfor ungrouped tabs. - برجسته شده
بولی اختیاری
Whether the tabs are highlighted.
- شاخص
number optional
The position of the tabs within their windows.
- lastFocusedWindow
بولی اختیاری
Whether the tabs are in the last focused window.
- خاموش
بولی اختیاری
Chrome 45+Whether the tabs are muted.
- سنجاق شده
بولی اختیاری
Whether the tabs are pinned.
- splitViewId
number optional
Chrome 140+The ID of the Split View that the tabs are in, or
tabs.SPLIT_VIEW_ID_NONEfor tabs that aren't in a Split View. - وضعیت
TabStatus optional
The tab loading status.
- عنوان
string optional
Match page titles against a pattern. This property is ignored if the extension does not have the
"tabs"permission or host permissions for the page. - آدرس اینترنتی
string | string[] optional
Match tabs against one or more URL patterns . Fragment identifiers are not matched. This property is ignored if the extension does not have the
"tabs"permission or host permissions for the page. - windowId
number optional
The ID of the parent window, or
windows.WINDOW_ID_CURRENTfor the current window . - windowType
WindowType optional
The type of window the tabs are in.
- تماس برگشتی
function optional
The
callbackparameter looks like:(result: Tab[]) => void
- نتیجه
Tab []
بازگشتها
Promise< Tab []>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
reload()
chrome.tabs.reload(
tabId?: number,
reloadProperties?: object,
callback?: function,
): Promise<void>
Reload a tab.
پارامترها
- tabId
number optional
The ID of the tab to reload; defaults to the selected tab of the current window.
- reloadProperties
object optional
- bypassCache
بولی اختیاری
Whether to bypass local caching. Defaults to
false.
- تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
remove()
chrome.tabs.remove(
tabIds: number | number[],
callback?: function,
): Promise<void>
Closes one or more tabs.
پارامترها
- tabIds
number | number[]
The tab ID or list of tab IDs to close.
- تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
removeCSS()
chrome.tabs.removeCSS(
tabId?: number,
details: DeleteInjectionDetails,
callback?: function,
): Promise<void>
Replaced by scripting.removeCSS in Manifest V3.
Removes from a page CSS that was previously injected by a call to scripting.insertCSS .
پارامترها
- tabId
number optional
The ID of the tab from which to remove the CSS; defaults to the active tab of the current window.
- جزئیات
Details of the CSS text to remove. Either the code or the file property must be set, but both may not be set at the same time.
- تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Chrome 88+Resolves when all the CSS has been removed.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
sendMessage()
chrome.tabs.sendMessage(
tabId: number,
message: any,
options?: object,
callback?: function,
): Promise<any>
Sends a single message to the content script(s) in the specified tab. The runtime.onMessage event is fired in each content script running in the specified tab for the current extension.
پارامترها
- tabId
شماره
- پیام
هر
The message to send. This message should be a JSON-ifiable object.
- گزینهها
object optional
- تماس برگشتی
function optional
Chrome 99+The
callbackparameter looks like:(response: any) => void
- پاسخ
هر
The JSON response object sent by the handler of the message.
بازگشتها
Promise<any>
Chrome 99+Promise that resolves with the response from the content script. If an error occurs while connecting to the specified tab, the promise will be rejected.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
sendRequest()
chrome.tabs.sendRequest(
tabId: number,
request: any,
callback?: function,
): Promise<any>
Please use runtime.sendMessage .
Sends a single request to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The extension.onRequest event is fired in each content script running in the specified tab for the current extension.
پارامترها
- tabId
شماره
- درخواست
هر
- تماس برگشتی
function optional
Chrome 99+The
callbackparameter looks like:(response: any) => void
- پاسخ
هر
The JSON response object sent by the handler of the request. If an error occurs while connecting to the specified tab, the promise will be rejected.
بازگشتها
Promise<any>
Chrome 99+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
setZoom()
chrome.tabs.setZoom(
tabId?: number,
zoomFactor: number,
callback?: function,
): Promise<void>
Zooms a specified tab.
پارامترها
- tabId
number optional
The ID of the tab to zoom; defaults to the active tab of the current window.
- zoomFactor
شماره
The new zoom factor. A value of
0sets the tab to its current default zoom factor. Values greater than0specify a (possibly non-default) zoom factor for the tab. - تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Chrome 88+Resolves after the zoom factor has been changed.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
setZoomSettings()
chrome.tabs.setZoomSettings(
tabId?: number,
zoomSettings: ZoomSettings,
callback?: function,
): Promise<void>
Sets the zoom settings for a specified tab, which define how zoom changes are handled. These settings are reset to defaults upon navigating the tab.
پارامترها
- tabId
number optional
The ID of the tab to change the zoom settings for; defaults to the active tab of the current window.
- zoomSettings
Defines how zoom changes are handled and at what scope.
- تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Chrome 88+Resolves after the zoom settings are changed.
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
ungroup()
chrome.tabs.ungroup(
tabIds: number | [number, ...number[]],
callback?: function,
): Promise<void>
Removes one or more tabs from their respective groups. If any groups become empty, they are deleted.
پارامترها
- tabIds
number | [number, ...number[]]
The tab ID or list of tab IDs to remove from their respective groups.
- تماس برگشتی
function optional
The
callbackparameter looks like:() => void
بازگشتها
قول<void>
Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
update()
chrome.tabs.update(
tabId?: number,
updateProperties: object,
callback?: function,
): Promise<Tab | undefined>
Modifies the properties of a tab. Properties that are not specified in updateProperties are not modified.
پارامترها
- tabId
number optional
Defaults to the selected tab of the current window .
- updateProperties
شیء
- فعال
بولی اختیاری
Whether the tab should be active. Does not affect whether the window is focused (see
windows.update). - autoDiscardable
بولی اختیاری
Chrome 54+Whether the tab should be discarded automatically by the browser when resources are low.
- برجسته شده
بولی اختیاری
Adds or removes the tab from the current selection.
- خاموش
بولی اختیاری
Chrome 45+Whether the tab should be muted.
- openerTabId
number optional
The ID of the tab that opened this tab. If specified, the opener tab must be in the same window as this tab.
- سنجاق شده
بولی اختیاری
Whether the tab should be pinned.
- انتخاب شده
بولی اختیاری
منسوخ شدهPlease use highlighted .
Whether the tab should be selected.
- آدرس اینترنتی
string optional
A URL to navigate the tab to. JavaScript URLs are not supported; use
scripting.executeScriptinstead.
- تماس برگشتی
function optional
The
callbackparameter looks like:(tab?: Tab) => void
بازگشتها
Promise< Tab | undefined>
Chrome 88+Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.
رویدادها
onActivated
chrome.tabs.onActivated.addListener(
callback: function,
)
Fires when the active tab in a window changes. Note that the tab's URL may not be set at the time this event fired, but you can listen to onUpdated events so as to be notified when a URL is set.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(activeInfo: object) => void
- activeInfo
شیء
- tabId
شماره
The ID of the tab that has become active.
- windowId
شماره
The ID of the window the active tab changed inside of.
onActiveChanged
chrome.tabs.onActiveChanged.addListener(
callback: function,
)
Please use tabs.onActivated .
Fires when the selected tab in a window changes. Note that the tab's URL may not be set at the time this event fired, but you can listen to tabs.onUpdated events so as to be notified when a URL is set.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, selectInfo: object) => void
- tabId
شماره
- selectInfo
شیء
- windowId
شماره
The ID of the window the selected tab changed inside of.
onAttached
chrome.tabs.onAttached.addListener(
callback: function,
)
Fired when a tab is attached to a window; for example, because it was moved between windows.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, attachInfo: object) => void
- tabId
شماره
- attachInfo
شیء
- newPosition
شماره
- newWindowId
شماره
onCreated
chrome.tabs.onCreated.addListener(
callback: function,
)
Fired when a tab is created. Note that the tab's URL and tab group membership may not be set at the time this event is fired, but you can listen to onUpdated events so as to be notified when a URL is set or the tab is added to a tab group.
onDetached
chrome.tabs.onDetached.addListener(
callback: function,
)
Fired when a tab is detached from a window; for example, because it was moved between windows.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, detachInfo: object) => void
- tabId
شماره
- detachInfo
شیء
- oldPosition
شماره
- oldWindowId
شماره
onHighlightChanged
chrome.tabs.onHighlightChanged.addListener(
callback: function,
)
Please use tabs.onHighlighted .
Fired when the highlighted or selected tabs in a window changes.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(selectInfo: object) => void
- selectInfo
شیء
- tabIds
number[]
All highlighted tabs in the window.
- windowId
شماره
The window whose tabs changed.
onHighlighted
chrome.tabs.onHighlighted.addListener(
callback: function,
)
Fired when the highlighted or selected tabs in a window changes.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(highlightInfo: object) => void
- highlightInfo
شیء
- tabIds
number[]
All highlighted tabs in the window.
- windowId
شماره
The window whose tabs changed.
onMoved
chrome.tabs.onMoved.addListener(
callback: function,
)
Fired when a tab is moved within a window. Only one move event is fired, representing the tab the user directly moved. Move events are not fired for the other tabs that must move in response to the manually-moved tab. This event is not fired when a tab is moved between windows; for details, see tabs.onDetached .
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, moveInfo: object) => void
- tabId
شماره
- moveInfo
شیء
- fromIndex
شماره
- toIndex
شماره
- windowId
شماره
onRemoved
chrome.tabs.onRemoved.addListener(
callback: function,
)
Fired when a tab is closed.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, removeInfo: object) => void
- tabId
شماره
- removeInfo
شیء
- isWindowClosing
بولی
True when the tab was closed because its parent window was closed.
- windowId
شماره
The window whose tab is closed.
onReplaced
chrome.tabs.onReplaced.addListener(
callback: function,
)
Fired when a tab is replaced with another tab due to prerendering or instant.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(addedTabId: number, removedTabId: number) => void
- addedTabId
شماره
- removedTabId
شماره
onSelectionChanged
chrome.tabs.onSelectionChanged.addListener(
callback: function,
)
Please use tabs.onActivated .
Fires when the selected tab in a window changes.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, selectInfo: object) => void
- tabId
شماره
- selectInfo
شیء
- windowId
شماره
The ID of the window the selected tab changed inside of.
onUpdated
chrome.tabs.onUpdated.addListener(
callback: function,
)
Fired when a tab is updated.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(tabId: number, changeInfo: object, tab: Tab) => void
- tabId
شماره
- changeInfo
شیء
- قابل شنیدن
بولی اختیاری
Chrome 45+The tab's new audible state.
- autoDiscardable
بولی اختیاری
Chrome 54+The tab's new auto-discardable state.
- دور انداخته شده
بولی اختیاری
Chrome 54+The tab's new discarded state.
- favIconUrl
string optional
The tab's new favicon URL.
- یخ زده
بولی اختیاری
Chrome 132+The tab's new frozen state.
- groupId
number optional
Chrome 88+The tab's new group.
- mutedInfo
MutedInfo optional
Chrome 46+The tab's new muted state and the reason for the change.
- سنجاق شده
بولی اختیاری
The tab's new pinned state.
- splitViewId
number optional
Chrome 140+The tab's new Split View.
- وضعیت
TabStatus optional
The tab's loading status.
- عنوان
string optional
Chrome 48+The tab's new title.
- آدرس اینترنتی
string optional
The tab's URL if it has changed.
- تب
onZoomChange
chrome.tabs.onZoomChange.addListener(
callback: function,
)
Fired when a tab is zoomed.
پارامترها
- تماس برگشتی
تابع
The
callbackparameter looks like:(ZoomChangeInfo: object) => void
- ZoomChangeInfo
شیء
- newZoomFactor
شماره
- oldZoomFactor
شماره
- tabId
شماره
- zoomSettings