# Is there a Nettalk JSON example app to communicate with Firefox via its Native messaging?

**URL:** <https://clarionhub.com/t/is-there-a-nettalk-json-example-app-to-communicate-with-firefox-via-its-native-messaging/7974>\
**Category:** questions\
**Tags:** nettalk, json\
**Created:** [March 1, 2025, 8:04pm UTC](https://clarionhub.com/t/is-there-a-nettalk-json-example-app-to-communicate-with-firefox-via-its-native-messaging/7974 "2025-03-01T20:04:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [March 1, 2025, 8:04pm UTC](https://clarionhub.com/t/is-there-a-nettalk-json-example-app-to-communicate-with-firefox-via-its-native-messaging/7974/1 "2025-03-01T20:04:35Z")

</div>

Following on from this:

> [@Anyone hooked a Clarion DLL into Javascript using JS-Ctypes?](https://clarionhub.com/t/anyone-hooked-a-clarion-dll-into-javascript-using-js-ctypes/7973):
>
> Anyone hooked a Clarion DLL into Javascript using JS-Ctypes? Wondered if there’s any gotcha’s? Its to extend some browser extensions I’m creating at the moment. Biggest issue I can see is when a Browser is running in a sandbox, but I’m hoping to find a way to punch out of any sandbox, probably by redirecting to a local nettalk server running outside of the sandbox. Edit. I would imagine I will also need to include things like this into my dll to help it get loaded properly. TIA Edit2…

Firefox extensions can communicate with dll's/binaries using its built in Native Messaging using json.

The firefox extension manifest file loads the exe, if its not loaded.

> Each message is serialized using JSON, UTF-8 encoded and is preceded with an unsigned 32-bit value containing the message length in native byte order.
> 
> The maximum size of a single message from the application is 1 MB. The maximum size of a message sent to the application is 4 GB.

I wondered if there a demo app in Nettalk? I'm guessing StringTheory will be processing the Json so maybe a Nettalk and StringTheory demo app?

TIA

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [March 2, 2025, 3:33am UTC](https://clarionhub.com/t/is-there-a-nettalk-json-example-app-to-communicate-with-firefox-via-its-native-messaging/7974/2 "2025-03-02T03:33:39Z")

</div>

I think your earlier idea of communicating to a server limited to localhost is a better approach.

For starters that is cross-browser compatible, although limited to machines running windows. If that client opened a websocket connection then the external server can “push” things at the browser.

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [March 3, 2025, 2:02pm UTC](https://clarionhub.com/t/is-there-a-nettalk-json-example-app-to-communicate-with-firefox-via-its-native-messaging/7974/3 "2025-03-03T14:02:53Z")

</div>

> [@Bruce](#):
>
> I think your earlier idea of communicating to a server limited to localhost is a better approach.

I’d agree, if javascript ctypes was enabled still, it would load a exe/dll instance for each tab which could eat ram quickly, however the Native Messaging appears to have the ability to eat ram by calling multiple instances of the exe/dll, unless a Mutex can restrict the exe/dll to a single instance, that I’ve yet to establish at this stage.

> **[Native messaging - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging)**
>
> Native messaging enables an extension to exchange messages with a native application, installed on the user's computer. The native messaging serves the extensions without additional accesses over the web.

> #### Connectionless messaging
> 
> A new instance of the app is created for each message. The app passes two arguments when starting:

So it looks like Connection-based messaging is the most resource efficient, using Background Scripts only.

> **[Content scripts - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#communicating_with_background_scripts)**
>
> A content script is a part of your extension that runs in the context of a web page. It can read and modify page content using the standard Web APIs. Content script behavior is similar to scripts that are part of a website, such as those loaded using...

> **[Background scripts - Mozilla | MDN](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts)**
>
> Background scripts or a background page enable you to monitor and react to events in the browser, such as navigating to a new page, removing a bookmark, or closing a tab.

This has some advantages though…

> ## [Background script environment](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts#background_script_environment)
> 
> ### [DOM APIs](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Background_scripts#dom_apis)
> 
> Background scripts run in the context of a special page called a background page. This gives them a [`window`](https://developer.mozilla.org/en-US/docs/Web/API/Window) global, along with all the standard DOM APIs provided by that object.

So I’m guessing here, Nettalk would just need to be set up as a port listener for the UTF-8 JSON data, and then respond accordingly, but it appears that the Firefox extension always need to initiate the port communication first, which would also mean ensuring the exe/dll is loaded.

We are responsible for installing the exe/dll as well and the only way to install a exe/dll within the confines of windows appears to be to write a batch file because python isnt always installed on a windows pc and then use the batch file to install the exe/dll or load it accordingly.

> #### App manifest
> 
> In the example above, the native application is a Python script. It can be difficult to get Windows to run Python scripts reliably in this way, so an alternative is to provide a `.bat` file, and link to that from the application’s manifest:

One other benefit of the batch file, would be testing for later versions and automatically installing them, outside of the firefox extension updates route.

I havent found out if powershell scripts can be used, but powershell can be disabled using group policy or even not installed using methods like the autounattend.xml where as batch files cant be disabled.

> **[Generate autounattend.xml files for Windows 10/11](https://schneegans.de/windows/unattend-generator/)**

Only other thing I need to establish is automatically installing the extension. Kaspersky Anti Virus installs its browser extension automatically when installing their product onto windows, which I like because its so seamless, so just need to track that functionality down and then I think it would be possible to knock something up, once I get my hands on a new Clarion IDE.

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [March 3, 2025, 2:28pm UTC](https://clarionhub.com/t/is-there-a-nettalk-json-example-app-to-communicate-with-firefox-via-its-native-messaging/7974/4 "2025-03-03T14:28:09Z")

</div>

> [@RchdR](#):
>
> So I’m guessing here, Nettalk would just need to be set up as a port listener for the UTF-8 JSON data, and then respond accordingly, but it appears that the Firefox extension always need to initiate the port communication first, which would also mean ensuring the exe/dll is loaded.

Well, yes exactly. That’s what I mean by a server listening on locahost. It has to be running in order to listen. The browser has to initiate the connection because it is the client.

> [@RchdR](#):
>
> We are responsible for installing the exe/dll as well and the only way to install a exe/dll within the confines of windows appears to be to write a batch file

Or just run a regular windows install of your program on the box. Or just copy the EXE and DLL’s onto the box. It all depends on your context here. Not sure how batch files or python come into the mix…

---

<div class="post-metadata">

**Author:** ![RchdR](https://clarionhub.com/letter_avatar_proxy/v4/letter/r/d78d45/32.png) [@RchdR](https://clarionhub.com/u/RchdR)\
**Post date:** [March 3, 2025, 3:02pm UTC](https://clarionhub.com/t/is-there-a-nettalk-json-example-app-to-communicate-with-firefox-via-its-native-messaging/7974/5 "2025-03-03T15:02:10Z")

</div>

> [@Bruce](#):
>
> Not sure how batch files or python come into the mix…

I got the impression there is some security restriction which firefox applies, ie it wont interact wirh a server unless its specified in the manifest.

Until I try I wont know if this is the case or not, but from a practicality POV, installing everything in one go when the extension is installed would be preferred rather than seperate manual installation processes.
