refactor: clipper screenshot (#2325)

This commit is contained in:
Aman Harwara
2023-05-05 20:12:44 +05:30
committed by GitHub
parent 313ce08c15
commit 2b845e814e
8 changed files with 65 additions and 24 deletions

View File

@@ -1,4 +1,4 @@
import { runtime, action, browserAction, windows, storage } from 'webextension-polyfill'
import { runtime, action, browserAction, windows, storage, tabs } from 'webextension-polyfill'
import { ClipPayload, RuntimeMessage, RuntimeMessageTypes } from '../types/message'
const isFirefox = navigator.userAgent.indexOf('Firefox/') !== -1
@@ -22,11 +22,15 @@ const openPopupAndClipSelection = async (payload: ClipPayload) => {
void openPopup()
}
runtime.onMessage.addListener((message: RuntimeMessage) => {
runtime.onMessage.addListener(async (message: RuntimeMessage) => {
if (message.type === RuntimeMessageTypes.OpenPopupWithSelection) {
if (!message.payload) {
return
}
void openPopupAndClipSelection(message.payload)
} else if (message.type === RuntimeMessageTypes.CaptureVisibleTab) {
return await tabs.captureVisibleTab(undefined, {
format: 'png',
})
}
})