Javascript

Open the side panel by default in google chrome extension

To open the side panel by default in google Chrome extension, you can use the Side Panel API introduced in Chrome extensions. You’ll need to configure your extension to register the sidebar (side panel)
and ensure it’s enabled automatically when the extension is installed or updated. Follow the steps below to achieve it:

 

1. Configure manifest.json

Include the side_panel property to define the default behavior of the sidebar.

manifest.json:

{
    manifest_version: 3,
    name: "Default Sidebar Extension",
    version: "1.0",
    description: "Opens a sidebar by default",
    permissions: ["sidePanel"],
    background: {
        service_worker: "background.js",
    },
    side_panel: {
        default_path: "sidebar.html",
    },
    action: {
        default_title: "Default Sidebar",
    },
}

 

2. Create the Sidebar HTML

Create the file sidebar.html that will be displayed in the sidebar.

sidebar.html:

<!DOCTYPE html>
<html>
    <head>
        <title>Sidebar</title>
    </head>
    <body>
        <h1>Welcome to the Sidebar</h1>
        <p>This is a default sidebar panel that opens automatically.</p>
    </body>
</html>

 

3. Automatically Enable the Sidebar

Use a background script to ensure the sidebar is enabled whenever the extension is installed or updated.

background.js:

chrome.runtime.onInstalled.addListener(() => {
 chrome.sidePanel.setOptions({
  path: "sidebar.html",
  enabled: true
 }, () => {
  console.log("Sidebar is enabled by default.");
 });
});
S M Zahed Kamal

Recent Posts

PHP to remove unnecessary key and value pairs from any multi-dimensional array

Today I will share a snippet I've used in a project. Using that function, you…

2 years ago

Use vanilla JavaScript to make Ajax request

JavaScript AJAX (Asynchronous JavaScript and XML) is a technique that gives the ability to send…

3 years ago

Add animation to bootstrap carousel elements

By default, Bootstrap carousel has no way to add animations to carousel elements. Here I'm…

3 years ago

Create custom pagination template in Laravel

Laravel comes up with a paginator that generates HTML compatible with the Tailwind CSS framework.…

3 years ago

Add Bootstrap Icons in SASS or SCSS

Bootstrap introduced their icons collection in November 2019 as Bootstrap Icons (v1.0.0-alpha). At that time,…

3 years ago

Create autocomplete using vanilla JavaScript

To create autocomplete feature for input field(s), HTML's datalist tag can be the easiest solution.…

3 years ago