Charles
  • Introduction
    • 👋Welcome
  • Getting started
    • Quickstart guide
  • Opening actions
    • Popup, side bar and modal options
    • Trigger the extension with a floating button
    • Open the extension automatically on specific URLs
  • Key features
    • Features overview
    • Open website on install / uninstall
    • Get tab info
    • Get text selected by user
    • Get element text
    • Get element HTML
    • Set element inner text
    • Set element inner HTML
    • Open URL in sidebar modal
    • Open URL in fullscreen modal
    • Copy text to clipboard
    • Populate an input field
    • Simulate mouse click on an element
    • Capture screenshot
    • Open URL in new tab
    • Show native alert
    • Set an extension badge color and text
    • Change extension icon
    • Close extension
    • Save to Chrome storage
    • Injecting custom javascript
  • Extending Charles
    • Extending Charles with your own Javascript
  • Publishing to the Chrome Webstore
    • Prepare extension for submission
    • Registering as a Chrome Webstore developer
    • Publishing your extension
  • FAQ
    • Common questions
  • Troubleshooting
    • Charles Data Elements do not receive any values
    • Cannot log in (cookie issues)
    • Support
Powered by GitBook
On this page
  1. Opening actions

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.

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

// 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);
    });
};

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

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

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.

PreviousPopup, side bar and modal optionsNextOpen the extension automatically on specific URLs

Last updated 5 months ago