Skip to content
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

C# Background Worker? #49

Closed
Catchawink opened this issue Jan 3, 2023 · 1 comment
Closed

C# Background Worker? #49

Catchawink opened this issue Jan 3, 2023 · 1 comment

Comments

@Catchawink
Copy link

Catchawink commented Jan 3, 2023

Hey! So I might have some basic misunderstandings of this framework--but I'm trying to create a Blazor web extension that changes the rendering of a content script based on an option added to the user's right-click context menu. So if the user right clicks a portion of text on a web page and presses the web extension option, they'll receive a read-out from the content script based on the selected text.

I was able to add a right-click option by interfacing with the web extension API in my extension's popup page (Popup.razor)--but that only seems to execute once the popup has been opened. So I tried adding the same code to my content script (ContentScript.razor) to reliably add the right-click option and hook it to the content script--but it appears as though content scripts can't access the full web extension/browser API.

I'm not sure how to accomplish this. Is there a simple way to access the full web extension API using a C# script running reliably in the background? I just want to control menu options/tabs/etc. using a background script in C#, ideally not so different from what's possible in Javascript using BackgroundWorker.js.

@mingyaulee
Copy link
Owner

Hi, from what I understood of your use case, the user would first select some text, then right click to view the context menu, select an action added to the context menu by the extension, and the selected text will be read out.

One possible solution would be to have a background worker listening to messages from the content script. But this means that you have to write it in JS. It's not possible to add listeners using Blazor because all listeners have to be registered synchronously.

With manifest V3 there is no persistent background (although there is a proposal) so the most optimum way would be to write it in JS for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants