# Browser extension: making messages available externally

**URL:** <https://forum.clockify.me/t/browser-extension-making-messages-available-externally/846>\
**Category:** Clockify API\
**Created:** [April 14, 2021, 6:43pm UTC](https://forum.clockify.me/t/browser-extension-making-messages-available-externally/846 "2021-04-14T18:43:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aleksandr\_Varnin](https://forum.clockify.me/user_avatar/forum.clockify.me/aleksandr_varnin/32/575_2.png) [@Aleksandr\_Varnin](https://forum.clockify.me/u/Aleksandr_Varnin)\
**Post date:** [April 14, 2021, 6:43pm UTC](https://forum.clockify.me/t/browser-extension-making-messages-available-externally/846/1 "2021-04-14T18:43:07Z")

</div>

Hello!  
I’m playing around with Clockify browser extension code that lives [here](https://github.com/clockify/browser-extension).

[Here](https://github.com/clockify/browser-extension/blob/84633b12a9b3fcd58c203e932be0d47f8384df3c/src/application-types/extension.js#L127) the extension is setting up some message handlers using `runtime.onMessage.addListener` which receive messages from other parts of the extension.

I have an idea about building an extension that is using Clockify. I need start timer/stop timer capabilities but I don’t want to maintain the implementation on my own. Instead I would prefer using what’s already done in the Clockify browser extension.

I could just send messages to the Clockify extesion using something like this:

```auto
   browser.runtime.sendMessage({
     extensionId: 'pmjeegjhjdlccodhacdgbgfagbpmccpe',
     eventName: 'startWithDescription',
     timeEntryOptions: timeEntryOptionsInvoked
   }, () => {...});

```

However this requires the original Clockify extension to accept the messages extrenally, so beside `runtime.onMessage.addListener` we would also need to set the same handler as `runtime.onExternalMessage.addListener`.

This way operations from the Clockify extensions like `startWithDescription`, `endInProgress` and `submitTime` could be available to other extensions and I could build some custom business logic that is sending messages to the Clockify extension and thus using this messages as an API.

@clockify do you think this is something acceptable from your side: adding support for external messages from other extensions? Would you accept a PR with such change?

---

<div class="post-metadata">

**Author:** ![clockify](https://forum.clockify.me/user_avatar/forum.clockify.me/clockify/32/2102_2.png) [@clockify](https://forum.clockify.me/u/clockify)\
**Post date:** [April 15, 2021, 7:16am UTC](https://forum.clockify.me/t/browser-extension-making-messages-available-externally/846/2 "2021-04-15T07:16:49Z")

</div>

That’s interesting, thanks for the suggestion! It sounds simple and doesn’t introduce complications, so there shouldn’t issues with accepting the PR.

Just send us the PR on Github, and out development team will take it from there.

---

<div class="post-metadata">

**Author:** ![SlavkoPar](https://forum.clockify.me/user_avatar/forum.clockify.me/slavkopar/32/593_2.png) [@SlavkoPar](https://forum.clockify.me/u/SlavkoPar)\
**Post date:** [April 27, 2021, 12:15pm UTC](https://forum.clockify.me/t/browser-extension-making-messages-available-externally/846/3 "2021-04-27T12:15:43Z")

</div>

Very soon we are going to deploy latest version of ‘clockify/browser-extension’ at

> **[clockify/browser-extension](https://github.com/clockify/browser-extension)**
>
> Clockify Browser Extension. Contribute to clockify/browser-extension development by creating an account on GitHub.

We are going to enable Cross-extension messaging, exposing a public API that other extensions can take advantage of.

Here is example of ussage:

chrome.runtime.onMessageExternal.addListener(  
function(request, sender, sendResponse) {  
if (sender.id == blocklistedExtension)  
return; // don’t allow this extension access  
else if (request.getTargetData)  
sendResponse({targetData: targetData});  
});

---

<div class="post-metadata">

**Author:** ![SlavkoPar](https://forum.clockify.me/user_avatar/forum.clockify.me/slavkopar/32/593_2.png) [@SlavkoPar](https://forum.clockify.me/u/SlavkoPar)\
**Post date:** [June 17, 2021, 7:22am UTC](https://forum.clockify.me/t/browser-extension-making-messages-available-externally/846/4 "2021-06-17T07:22:43Z")

</div>

We enabled Cross-extension messaging, exposing a public API that other extensions can take advantage of.  
Here is the example of how your Extension can Start new Time Entry, or Stop it:

// Clockify Time Tracker / Cross-extension messaging.  
// External Extensions use Authentication and Settings of Clockify Time Tracker Extension.

```
const aBrowser = (isChrome || isEdge) ? chrome : browser;
// Clockify Time Tracker Extension ID
const extensionID = (isChrome || isEdge) 
        ? 'pmjeegjhjdlccodhacdgbgfagbpmccpe'
        : '{1262fc44-5ec9-4088-a7a7-4cd42f3f548d}';

// start new Time Entry
aBrowser.runtime.sendMessage(
    extensionID, 
    {
        eventName: 'startNewEntry',
        data: {
            description: 'studying',
            project: { name: '' || 'abc' || null },
            task: { name: '' || 'ttt' || null },
            billable: false || true || null,
            tags: ['media', 'social']
        }
    },
    (response) => {
        if (response) {
            const { entry, message } = response;
            console.log(entry, message);
        }
    }
);

// stop Entry in progress
aBrowser.runtime.sendMessage(
    extensionID, 
    {
        eventName: 'endInProgress'
    },
    (response) => {
        if (response) {
            const { entry, message } = response;
            console.log(entry, message);
        }
    }
);
```
