Files
page-assist/src/libs/get-html.ts

27 lines
617 B
TypeScript
Raw Normal View History

2024-02-02 22:01:16 +05:30
const _getHtml = () => {
const url = window.location.href
const html = document.documentElement.outerHTML
return { url, html }
}
export const getHtmlOfCurrentTab = async () => {
const result = new Promise((resolve) => {
chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => {
const tab = tabs[0]
const data = await chrome.scripting.executeScript({
target: { tabId: tab.id },
func: _getHtml
})
if (data.length > 0) {
resolve(data[0].result)
}
})
}) as Promise<{
url: string
html: string
}>
return result
}