Homepage    |    GitHub    |    API    |    FAQ

How can I refer the plugin settings from contentScript?

I'm developing a plugin that enables embedding PlantUML diagrams in markdown.

I have defined settings like below:

And I have tried to refer the settings from here in contentScript

But it seems that we can't use plugin's API from there.

How can I refer the plugin settings from contentScript?

Send a message to your plugin, get settings in the plugin, send the result back to the contentscript.

Thank you for your reply!

I have defined onMessage() which returns settings and tried to get the settings from contentScript,

But it seems not allowed for markdown-it plugin.

loadContentScripts: context.postMessage is not available to renderer content scripts

Hmm, I don't think that's possible actually. You can post messages from the HTML that the content script generates, but you can't when you instantiate the Markdown-it plugin. Maybe some way to do this should be provided via the context variable.

If I may make a suggestion, it would make sense to use a fence like this to delimit the UML code:

Bob -> Alice : Hello

That would be consistent with how it's done for Mermaid, Fountain, etc.

Thank you for the suggestion!
Now I'm using it as fence.

By the way, I want to switch PlantUML server by settings.
Currently I'm using a public PlantUML server. This means that we can't use this plugin with confidential information.

To switch the server, would you consider to give us a way to get settings from content script?

Yes I think we should add this. Calling postMessage at this point would be tricky because it's async, and that function is synchronous. Perhaps it's a matter of allowing to pass variables from the plugins via the context parameter.

1 Like

It's nice idea. I'm looking forward to the feature being implemented.

I do not recommend to provide it directly, because there are too many tool libraries for encapsulating postMessage/onMessage, the most typical one is ChromeLab’s comlink, ref: GitHub - GoogleChromeLabs/comlink: Comlink makes WebWorkers enjoyable.


@uphy I just went down this same path trying to modify your plugin to add the ability to change the PlantUML server.

For a variety of reasons I cannot use the public PlantUML server for work.

In the meantime--I'll just run a custom version of your plugin that hard-codes the change.