Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Google Chrome extension to set new tabs to a local HTML file and stylesheet

I'm trying to make an extension for Chrome to make new tabs load a local HTML file. I have partially succeeded in this, by adding a .json file to the main directory with the following code:

{
 "name": "Extension Name",
 "description": "Extension description",
 "version": "0.1",
 "incognito": "split",
 "chrome_url_overrides": {
  "newtab": "start.html"
 },
 "manifest_version": 2
}

This sort of works. Opening a new tab loads the HTML file, but the majority of the css doesn't work and none of the images load.

I don't want to install an extension from the web store to do this for me, as I would like to be able to distribute this in the future.

I have no experience at all with Google Chrome extensions, and I couldn't find anything relating to this specific issue elsewhere. Does anyone know what I'm doing wrong? Do I need to be do something else? Is this possible? Any help would be greatly appreciated.

like image 758
Intelta Avatar asked Oct 24 '25 15:10

Intelta


1 Answers

let me share I've made shortly.

This is the same manifest file you'd mentioned above

{
     "name": "Extension Name",
     "description": "Extension description",
     "version": "0.1",
     "incognito": "split",
     "chrome_url_overrides": {
      "newtab": "start.html"
     },
     "manifest_version": 2
}

I created a folder named assets in the root directory of chrome extension (that has the manifest.json file), where I created style.css and added an image file img.jpg.

.content p {
    font-size: 26px;
}
<!DOCTYPE html>
<html>
<head>
    <title>Hello</title>
    <link rel="stylesheet" type="text/css" href="assets/style.css">
</head>
<body>
<div class="content">
    <p>Hello world</p>
    <img src="assets/image.jpg">
</div>
</body>
</html>

This works on my end. I hope it would give you a hind on what went wrong there.

Thanks,

like image 58
Perfect Avatar answered Oct 27 '25 03:10

Perfect



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!