> For the complete documentation index, see [llms.txt](https://cranford-tech.gitbook.io/charles/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cranford-tech.gitbook.io/charles/opening-actions/trigger-the-extension-with-a-floating-button.md).

# Trigger the extension with a floating button

You can modify the source code so that a floating button is used to trigger a custom script that shows the Chrome extension.&#x20;

Check out the sample script customScript1.js which injects a yellow button into bubblehacks.io:

{% code overflow="wrap" lineNumbers="true" %}

```javascript
// Create a rounded floating button in the bottom right corner and inject into the DOM
let button = document.createElement("button");
button.innerHTML = "C"; // Button label
button.style.position = "fixed";
button.style.bottom = "20px";
button.style.right = "20px";
button.style.zIndex = "9999";
button.style.borderRadius = "50%"; // Makes the button round
button.style.width = "50px"; // Circle width
button.style.height = "50px"; // Circle height
button.style.lineHeight = "50px"; // Vertically align text
button.style.textAlign = "center"; // Horizontally align text
button.style.padding = "0"; // Adjust padding to 0 for alignment
button.style.backgroundColor = "yellow"; // Yellow background
button.style.color = "black"; // Black font color
button.style.border = "none";
button.style.cursor = "pointer";
button.style.boxShadow = "0 4px 8px rgba(0,0,0,0.3)"; // More prominent shadow
document.body.appendChild(button);

button.onclick = function () {
    // Send a message to background.js to open the iframe sidebar
    chrome.runtime.sendMessage({ type: "openIframeSidebar", url: url, width: width }, function (response) {
        console.log(response.status);
    });
};

```

{% endcode %}

This is how the yellow button will look on the page specified (in this case bubblehacks.io):

<div align="left"><figure><img src="/files/9TrliSSK0OPgtpKm7HgU" alt=""><figcaption></figcaption></figure></div>

**Important:** Make sure the js file is  injected into the appropriate page and has appropriate host permissions by adjusting the manifest.js

<div align="left"><figure><img src="/files/7cu7RnvnuSwTN5fw2Oj8" alt=""><figcaption></figcaption></figure></div>

This only works for the sidebar or full screen modals. Not for the extension popup. If you need a popup, please adjust the sidebar CSS to make it look like a popup.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://cranford-tech.gitbook.io/charles/opening-actions/trigger-the-extension-with-a-floating-button.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
