jonah
jonah
PD🧩 Plasmo Developers
Created by jonah on 6/12/2024 in #👾extension
Storage API syncing
Hi there, I was wondering if there was any information on getting the storage API to work with cross browser syncing (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/storage/sync).
1 replies
PD🧩 Plasmo Developers
Created by jonah on 7/21/2023 in #👾extension
Modifying HttpOnly cookies
There is a specific cookie that I am trying to extend the expiration date of, but I can't figure out how to modify it. At first, I tried modifying it with a content.ts file that edits the document.cookies, but that doesn't include httpOnly cookies. I then made a BSGW and tried to use the webReqeuest API to listen to the onHeadersReceived event, but that also doesn't include the set-cookie headers. Does anyone have any ideas on how to go about doing this?
1 replies
PD🧩 Plasmo Developers
Created by jonah on 6/20/2023 in #👟framework
Offscreen + Messaging API issue
Hello, I am trying to create an offscreen document for copying text to clipboard. I am trying to follow some of the examples I found in this issue: https://github.com/PlasmoHQ/plasmo/issues/527. In my background.ts file, I am trying to send a message to my offscreen.ts file like this:
const resp = await sendToBackground({
name: "offscreen",
body: {
alias
}
})
const resp = await sendToBackground({
name: "offscreen",
body: {
alias
}
})
this is the offscreen.ts file:
import OFFSCREEN_DOCUMENT_PATH from "url:~src/offscreen.html"

import type { PlasmoMessaging } from "@plasmohq/messaging"

const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
if (!(await chrome.offscreen.hasDocument())) {
await chrome.offscreen.createDocument({
url: OFFSCREEN_DOCUMENT_PATH,
reasons: [chrome.offscreen.Reason.CLIPBOARD],
justification: "Writing text to clipboard"
})
}

const textEl: HTMLTextAreaElement = document.querySelector("#text")!
textEl.value = req.body.alias
textEl.select()
document.execCommand("copy")

res.send(true)
}

export default handler
import OFFSCREEN_DOCUMENT_PATH from "url:~src/offscreen.html"

import type { PlasmoMessaging } from "@plasmohq/messaging"

const handler: PlasmoMessaging.MessageHandler = async (req, res) => {
if (!(await chrome.offscreen.hasDocument())) {
await chrome.offscreen.createDocument({
url: OFFSCREEN_DOCUMENT_PATH,
reasons: [chrome.offscreen.Reason.CLIPBOARD],
justification: "Writing text to clipboard"
})
}

const textEl: HTMLTextAreaElement = document.querySelector("#text")!
textEl.value = req.body.alias
textEl.select()
document.execCommand("copy")

res.send(true)
}

export default handler
Heres my offscreen.html:
<!DOCTYPE html>
<html>

<head>
<title>Offscreen</title>
</head>

<body>
<script src="offscreen.ts" type="module"></script>
</body>

</html>
<!DOCTYPE html>
<html>

<head>
<title>Offscreen</title>
</head>

<body>
<script src="offscreen.ts" type="module"></script>
</body>

</html>
But, when I try this, I get this error: Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist. Which I'm guessing means it can't find the message handler. Am I supposed to put the message handler in a different place or create the offscreen document in a different file? I would really appreciate if someone could help me fix this.
28 replies
PD🧩 Plasmo Developers
Created by jonah on 6/14/2023 in #👾extension
Document is not defined on chrome mv3 in a background.ts file
Hello, I have created a context menu that copies something to your clipboard. This is the function I'm using:
function copyToClipboard(text: string) {
const el = document.createElement("textarea")
el.value = text
document.body.appendChild(el)
el.select()
document.execCommand("copy")
document.body.removeChild(el)
}
function copyToClipboard(text: string) {
const el = document.createElement("textarea")
el.value = text
document.body.appendChild(el)
el.select()
document.execCommand("copy")
document.body.removeChild(el)
}
This works fine with firefox but not on chrome. So, is there a better way to add a string to the users clipboard via a context menu listener event that works with chrome mv3?
70 replies
PD🧩 Plasmo Developers
Created by jonah on 12/27/2022 in #👟framework
onInstalled event with Plasmo
Hi! Is it possible to use the runtime.onInstalled event with Plasmo?
4 replies
PD🧩 Plasmo Developers
Created by jonah on 12/24/2022 in #👟framework
Best way to store JSON with storage API
Hello 😁 ! I am going to store some configuration data (in JSON) using the storage API. I am wondering what is the best way to do it using the usestorage hook. I was thinking of somehow using the onInit argument to parse the JSON but I'm not sure if that will work.
13 replies