RandomJay
RandomJay
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
Definitely, thank you. Much cleaner this way
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
Thank you again @filthytone and @Sam , I learned a lot here about some pretty esoteric things. Appreciate you both taking the time!
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
Thank you, ended up being a newbie question after all
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
Dang, you're 100% right, I was overcomplicating this by a lot. All I needed to do was:
const results = await new Promise((resolve, reject) => {
window.axe.run(
{
allowedOrigins: ["<unsafe_all_origins>"],
exclude: []
},
(err, results) => {
if (err) {
console.log(err)
reject(err)
} else {
resolve(results)
}
}
)
})
const results = await new Promise((resolve, reject) => {
window.axe.run(
{
allowedOrigins: ["<unsafe_all_origins>"],
exclude: []
},
(err, results) => {
if (err) {
console.log(err)
reject(err)
} else {
resolve(results)
}
}
)
})
And it works swimingly, all results displayed in the background script directly 🤦‍♂️
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
I'll def take a look. Here's the function at its most basic:
await window.axe.run(
{
allowedOrigins: ["<unsafe_all_origins>"],
exclude: []
},
async (err, results) => {
if (err) {
console.log(err)
}

return results
}
)
await window.axe.run(
{
allowedOrigins: ["<unsafe_all_origins>"],
exclude: []
},
async (err, results) => {
if (err) {
console.log(err)
}

return results
}
)
I think it's that the results only exist in the callback function, so i need to see if i can hoist it outta there 🙂
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
Thank you @Sam, this is a great example. I'll play with this and see if i can get it working. I'm 99% of the way there already. and @filthytone , the scripting API is my favorite approach becuase it's so simple, I don't really need to inject more than the window.axe object to run tests against. Maybe it's just the way i'm running the test that's preventing me from getting the results from the execution back, i'm probably stuck in a closure or something so i'll start there and then work my way back to the less trusted but more flexible options 👍
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
While we're playing with that, MASSIVE thank you, @filthytone , you really helped me out here
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
Knowing that I have the external script to fall back on, i'm happy to experiment with that too, let me switch over to relay and i'll tell you about that error. Does relay also require the externally_connectable flag in the manifest to be set?
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
I did, that resulted in a different error for me, unfortunately. Are you kidding?! i appreciate any and all help!
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
but that last one is the kicker, the response only returns a promise with the inject result, not the result of the function itself
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
basically I do this:
// Inject the axe script into the active tab
await chrome.scripting.executeScript({
target: {
tabId
},
files: ["axe.min.js"],
world: "MAIN"
})
// Configure axe
await chrome.scripting.executeScript({
target: {
tabId
},
func: configureAxe,
world: "MAIN"
})
// Run the test
await chrome.scripting.executeScript({
target: {
tabId
},
func: runA11yAudit,
world: "MAIN"
})
// Inject the axe script into the active tab
await chrome.scripting.executeScript({
target: {
tabId
},
files: ["axe.min.js"],
world: "MAIN"
})
// Configure axe
await chrome.scripting.executeScript({
target: {
tabId
},
func: configureAxe,
world: "MAIN"
})
// Run the test
await chrome.scripting.executeScript({
target: {
tabId
},
func: runA11yAudit,
world: "MAIN"
})
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
I actually started with that, but unfortunately there's no way to report the results BACK to the background without being in main unfortunately. I tried passing a callback along, but since functions aren't serializable I can't actually get the results back. Unless there's an easy way to do that that you know of? I'd much prefer that approach if there's a way
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
and at least make sure it's attributed to the right user. I already have auth enabled here, so i can probably use that too
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
so if i generate an id from the backend when the test is kicked off to ensure that the call is legitimate when i run the processing, that might be a good way to validate that the request is legit
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
Got it, so to be safe i should pass along some kind of payload for verification when i trigger the extension manually. Basically, my extension runs an automated accessibility test script against any webpage, and then reports back the findings via this external script so that I can process and highlight the issues in a dev-friendly way
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
"externally_connectable": {
"ids": [
"kel...ehg"
],
"matches": [
"http://*/*",
"https://*/*"
]
},
"externally_connectable": {
"ids": [
"kel...ehg"
],
"matches": [
"http://*/*",
"https://*/*"
]
},
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
of the manifest? one sec
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
btw, that worked! I was able to receive the message via the external route, thank you for the advice there. For anyone finding this later, the correct path was messages/external/handler.ts
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
Even if i explicitly defined my extension id in the manifest?
73 replies
PD🧩 Plasmo Developers
Created by RandomJay on 10/30/2024 in #🔰newbie
sendToBackground in MAIN world doesn't work even with extensionId provided
oh! trying that one sec
73 replies