# Extending Charles with your own Javascript

You can add your own JS to execute within an active tab and also pass values back to bubble. Please have a look at this tutorial: <https://share.descript.com/view/NARVH1XDUbL>

**Code snippet**

```javascript
//send message to parent window
var msg = {
    "requestType":"customFunction"
}
window.parent.postMessage(JSON.stringify(msg), "*");


//listening for messages from the parent window
window.addEventListener('message', function (event) {
    // create object from event.data
    eventdata = JSON.parse(event.data);
    if (eventdata.returnType == "h1") {
        console.log('Received h1: ', eventdata.value);
    }
}, false);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cranford-tech.gitbook.io/charles/extending-charles/extending-charles-with-your-own-javascript.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
