`HTML Page Appears Distorted When Accessed Through Chrome Extension`

It's my first time posting here, so I hope I've provided enough details for an easy resolution to my question.

I'm in the process of developing a flashcard system as a Google Chrome extension. The main page of the system is a single page that loads when the Browser Action button (located at the top right of the browser) is clicked.

The issue I'm facing is related to the appearance of the HTML file loaded by the extension. The text seems to have mysteriously "shrunk," indicating that while the CSS file is loading properly, the Javascript file is not being loaded. Although the Javascript doesn't directly impact the text appearance, I would like it to also load correctly for additional functionality.

Since Chrome extensions are new territory for me, I might be overlooking some crucial aspects in my setup.

If anyone can shed some light on why this "text shrinking" and "Javascript not loading" anomaly is occurring, I'd greatly appreciate your assistance.

Below is the code snippet I've been working with:

HTML (popup.html)

<!DOCTYPE html>
<html>
<head>
    <title>Drill</title>

    <link rel="stylesheet" type="text/css" href="drillstyle.css">
</head>
<body>

    <!-- Main Canvas -->
    <div id="canvasdiv">

        <canvas id="canvas" width="900" height="600"></canvas>

        <div id="canvascontextpara">
            <h3>This is a paragraph. This is a paragraph...</h3>
        </div>

    </div>

    <!-- Jquery -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
    <!-- Main JS-->
    <script src="drill.js"></script>
</body>
</html>

CSS (drillstyle.css)

#canvasdiv {
    width: 900px;
    height: 600px;
    border: 1px solid black;
    position: relative;
    margin: 0 auto; }

#canvascontextpara {
    position: absolute;
    top: 60px;
    left: 100px;
    width: 700px;
    height: 150px;
    text-align: center;
    font-family: 'Comic Sans MS';
    color: white;
    margin: 0 auto;
    z-index: 2;
    background: gray; }

canvas{ position: absolute; z-index: 1 }

body{ background-color: black;}

Main JavaScript (drill.js)

// JavaScript code here...

Google Chrome Extension Manifest File (manifest.json)

{
  // Manifest content here...

}

Extension JavaScript File (eventPage.js)

// Extension JavaScript code here...

Refer to the following images for a visual representation:

Desired look

However...

Current extension display

Thank you, Roy

Answer №1

In order to load external scripts, you must ensure they are allowed in the extension manifest due to the limitations of the content security policy.

Additionally, a style is injected into all extension pages which includes the following rule:

body {
    font-family: 'Droid Sans', Arial, sans-serif;
    font-size: 75%;
}

Update: One way to address this issue is by adding a style that overrides the default rule like so:

body {
    font-family: initial;
    font-size: initial;
}

To enable jQuery to load, you will need to whitelist the Google CDN. It's important to note that only the https version can be whitelisted, not http URLs. Include the following code snippet in your manifest.json file:

"content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'"

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A fresh PHP page escapes from the confines of an iframe and expands to occupy the entire

When calling a new url from inside an iframe, the goal is for the new url to break free from the confines of the iframe and appear full screen. The challenge lies in not having control over the call to the new php file, as it is initiated by a credit card ...

Button within ng-switch statement

Issue with switch button inside switch statement, only functioning correctly outside of the switch statement. See below for my code: <div ng-controller="LoginController as LC"> <div ng-switch on="view.name"> <div ng-switch-de ...

Hexadecimal characters are randomly injected into the source code of websites

On specific computers, strange hex codes are appearing randomly in the source code of our web pages across all tested browsers (Chrome, Safari, IE, and Firefox). They seem to occur approximately every 8000 characters with a new line before and after. Here& ...

What is the best way to incorporate polling into the code provided below? I specifically need to retrieve data from the given URL every 60 seconds. How should I go about achieving this

Can you assist me in integrating polling into the code below? <!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> <script src="https://code.highcharts.com/highcharts.js"> ...

Tips on setting a value to zero in Angular when there is no input

Is there a way to organize the data and show the PRN entries based on the date, for instance, when the month is January? If there is data for machine 1 with assetCode: PRN, it should be displayed under the header for children. Similarly, if there is data f ...

Issue with Vanilla JS not firing the shown event in Bootstrap tabs

I am struggling to identify when a tab is displayed using Vanilla JS, but the event doesn't seem to be working. Despite researching various solutions, none of them have been helpful in resolving this issue. Here's my current code snippet. var ...

Numerous web pages featuring the same title and navigation menus

Creating my personal academic website involves multiple pages that share a common structure. Question: I'm searching for a method to avoid duplicating the header and menu code in each HTML file. Is there an approach where I can store the code for the ...

How to incorporate a background image into a hyperlink?

I am working on a class that I have created, which is called .blueButton. It contains some CSS styling that makes it look like a button. .blueButton { /* Styling properties go here */ } To implement this button, I use the following HTML code: <a ...

Attempting to implement a jQuery function to toggle the visibility of the submenu

Hey there! After spending some time digging into this, I've hit a roadblock. I'm struggling to figure out how to keep the sub-menu active even when the mouse is no longer hovering over it, similar to how the bootstrap menu functions. Here' ...

What are the steps to applying strike-through text in Vue.js?

I am currently working on a to-do application using Vue.js and I want to implement a feature where the text rendered in HTML has a line through it when the user checks an item off the list. Here is the snippet of my code: <html> <head> & ...

The ng-style directive is not functioning properly

After selecting a category, I attempted to change the color using "ng-style" in my HTML code. However, it seems that the color change is not taking effect. This is the snippet from my HTML code: <div ng-repeat="item in ListExpense" ng-class-odd="&apos ...

Activate a function after selecting a file using the input type=file and showcase the file path by utilizing ng-repeat

<input type="file" id="file" name="file" ng-show="attachFile" /> <button type="button" ng-model="attach" ng-click="add()">Attach</button> <div class="panel panel-default" ng-show="displayAttachments"> <div class="panel-h ...

When you click on the collapsible header background, the content collapses, but the main icon does not update

I am currently using collapsible content from Bootstrap and I am encountering an issue with the icon not changing when I click on the collapsible-header background. Here is a visual representation of the problem: 1st part (not collapsed) 2nd part (After ...

The submission process for a multi-step form in Laravel appears to be malfunctioning

In my step bootstrap form, the submit method is not working. It's linked with jQuery, but if I remove the id then the continue button stops working. How can I take action using route submit without requiring jQuery validation? I only need the continue ...

Set up jQuery to execute code when the document is loaded and when

I'm looking for the most effective way to combine ready and ajaxStop in jQuery. Currently, my approach involves: jQuery(document).ready(function($) { $(document).bind('ready ajaxStop', function() { $('[rel=tooltip], [data-t ...

React DOM's offsetHeight prior to rendering

I am struggling to figure out how to position a React DOM element based on its offsetHeight. The issue is that I cannot determine the offsetHeight of an element that hasn't been created yet (so the height cannot be passed as a parameter to the render ...

Custom font not displaying on Chromecast receiver app

I have followed the specified steps to incorporate a custom font into an html canvas text field. Interestingly, the font displays correctly when accessed on the Desktop Chrome browser, but on the Chromecast receiver application, the font fails to load. Wha ...

Experiencing difficulties logging into Facebook with ngCordova

I'm currently working on a hybrid application that involves integrating Facebook login. After closely following the instructions outlined in this specific URL, I encountered the following error message: https://i.sstatic.net/Hf5QX.png Any assistance ...

jQuery dynamically updating calculations on a single row consecutively

Currently, I am in the process of developing a small table to calculate potential winnings from betting on a rubber duck race with specific odds for each duck. I have managed to get most of it working but have encountered an issue... Upon loading the pag ...

Stretching the limits: Combining and expanding your Styled Components theme

I am facing a situation where I have a component library built using Styled Components that has its own theme settings which are not meant to be overridden. Now, I need to incorporate this component library into another project that also uses Style Compone ...