-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement "to content script" via background page #29
Conversation
if (message.target) { | ||
const publicMethod = getContentScriptMethod(message.type); | ||
return handleCall( | ||
message, | ||
sender, | ||
publicMethod(message.target, ...message.args) | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core of the forwarder at this point. Information about the original sender is not preserved yet.
I think I will turn MessengerMeta
into an array where each step just prepends its own "sender" information, sort of like a stack trace.
const sendMessage = !browser.tabs | ||
? async () => browser.runtime.sendMessage(makeMessage(type, args, target)) | ||
: async () => | ||
browser.tabs.sendMessage( | ||
target.tabId, | ||
makeMessage(type, args), | ||
// `frameId` must be specified. If missing, the message is sent to every frame | ||
{ frameId: target.frameId ?? 0 } | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the current "routing" implementation.
Since getContentScriptMethod
is specific to content scripts, it's clear what the direction is: If we can't message the CS directly, we must contact the background page.
@@ -0,0 +1,33 @@ | |||
export async function ensureScripts(tabId: number): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey this looks familiar!
target?: Target; | ||
|
||
/** If the message is being sent to an intermediary receiver, also set the options */ | ||
options?: Target; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notification forwarding hasn't been implemented yet, so this is currently unused. I'll implement them separately
Test:
Next:
Notes: