# How to call a javascript function with the addon?

**URL:** <https://discourse.mozilla.org/t/how-to-call-a-javascript-function-with-the-addon/29593>\
**Category:** Development\
**Created:** [June 23, 2018, 11:49pm UTC](https://discourse.mozilla.org/t/how-to-call-a-javascript-function-with-the-addon/29593 "2018-06-23T23:49:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Userbad](https://avatars.discourse-cdn.com/v4/letter/u/b5ac83/32.png) [@Userbad](https://discourse.mozilla.org/u/Userbad)\
**Post date:** [June 23, 2018, 11:49pm UTC](https://discourse.mozilla.org/t/how-to-call-a-javascript-function-with-the-addon/29593/1 "2018-06-23T23:49:17Z")

</div>

Hello!  
I would like to create an addon that calls js functions on a web page.  
The function is defined inside a web page script and I can call it using the firefox console. How do I call the function from the add-on?

Thanks for your help!

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [June 24, 2018, 11:29am UTC](https://discourse.mozilla.org/t/how-to-call-a-javascript-function-with-the-addon/29593/2 "2018-06-24T11:29:25Z")

</div>

You can interact with the JS from a page using content scripts: [https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content\_scripts](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts)

---

<div class="post-metadata">

**Author:** ![Userbad](https://avatars.discourse-cdn.com/v4/letter/u/b5ac83/32.png) [@Userbad](https://discourse.mozilla.org/u/Userbad)\
**Post date:** [June 24, 2018, 8:22pm UTC](https://discourse.mozilla.org/t/how-to-call-a-javascript-function-with-the-addon/29593/3 "2018-06-24T20:22:59Z")

</div>

Thanks for your help.  
I used the content script but I still do not access the functions.

The script is defined in the web page:

//webpage

`<script type="text/javascript" src="lib/note.js"></script>`

```
//note.js
var a;

function test() {
	.....
}

```

The addon must call the function “test”.

Can you give me an example?  
Thanks.

---

<div class="post-metadata">

**Author:** ![freaktechnik](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/freaktechnik/32/37766_2.png) [@freaktechnik](https://discourse.mozilla.org/u/freaktechnik)\
**Post date:** [June 24, 2018, 10:24pm UTC](https://discourse.mozilla.org/t/how-to-call-a-javascript-function-with-the-addon/29593/4 "2018-06-24T22:24:52Z")

</div>

Hm, I thought this was linked from the content script guide, but I couldn’t see it at a quick glance, so here’s the direct link in case it really wasn’t linked from that article: [https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Sharing\_objects\_with\_page\_scripts#Accessing\_page\_script\_objects\_from\_content\_scripts](https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#Accessing_page_script_objects_from_content_scripts)

---

<div class="post-metadata">

**Author:** ![Userbad](https://avatars.discourse-cdn.com/v4/letter/u/b5ac83/32.png) [@Userbad](https://discourse.mozilla.org/u/Userbad)\
**Post date:** [June 25, 2018, 9:11am UTC](https://discourse.mozilla.org/t/how-to-call-a-javascript-function-with-the-addon/29593/5 "2018-06-25T09:11:08Z")

</div>

Thank you!  
it works!
