1
如何訪問選項卡的樣式信息?以下代碼記錄一個空對象。獲取頁面背景
tabs.activeTab.attach({
contentScript: 'self.port.emit(console.log(unsafeWindow.document.body.style);'
});
如何訪問選項卡的樣式信息?以下代碼記錄一個空對象。獲取頁面背景
tabs.activeTab.attach({
contentScript: 'self.port.emit(console.log(unsafeWindow.document.body.style);'
});
首先,您在內容腳本中缺少)
。然後你將返回值console.log
返回到端口。
但是我打算假設你從頁面的控制檯中獲得了一個空對象,從console.log
。 document.body.style
屬性可能仍爲空,因爲該屬性僅保留HTML元素的樣式屬性的內聯的值(請參閱https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style)。
您可能需要解析document.styleSheets或使用developer tools API來獲取當前渲染的背景。