Why do I get a Bootstrap JavaScript error in my Chrome Extension?

Viewed 47

I'm trying to create a Chrome extension where I have a button appear on Google's search result page, and onhover over the button, a modal appears.

I can get the modal to begin to appear(background gets dark), but get a JavaScript error before the actual modal box shows.

The error is:

Uncaught TypeError: Illegal invocation

return Element.prototype.querySelector.call(element, selector);

Any help is greatly appreciated. Thanks in advance!

manifest.json

{
    "manifest_version": 3,
    "name": "Button Modal",
    "description": "Button Modal",
    "version": "0.0.1",
    "icons": {
        "16": "./icons/icon-16x16.png",
        "36": "./icons/icon-36x36.png",
        "48": "./icons/icon-48x48.png",
        "120": "./icons/icon-120x120.png"
    },
    "content_scripts": [
        {
            "matches": ["https://*.google.com/*", "https://google.com/*"],
            "js": ["js/jquery-3.6.1.min.js", "js/bootstrap.bundle.js", "content-script.js"],
            "css": ["css/bootstrap.css", "css/content.css"],
            "run_at": "document_end"
        }
    ],
    "action": {
        "default_popup": "popup.html",
        "default_title": "Popup title"
    },
    "permissions": [
        "tabs",
        "storage"
    ]
}

content-script.js

$(document).ready(function(){
    $(".btn-sm").hover(function(){
        $("#exampleModalToggle").modal("show");
    });
});

//add modal after opening body tag
$("body").after("<div id='exampleModalToggle' className='modal fade'><div className='modal-dialog'><div className='modal-content'><div className='modal-header'><h5 className='modal-title'>Modal Title</h5><button type='button' className='close' data-dismiss='modal'>&times;</button></div><div className='modal-body'><p>This is a simple Bootstrap modal. Click the 'Cancel button', 'cross icon' or 'dark gray area' to close or hide the modal.</p></div></div></div></div>");


$("#result-stats nobr").after(" <button type='button' class='btn btn-warning btn-sm'>BUTTON</button>");

1 Answers

I had used className in my code instead of class. This in turn caused the Bootstrap interpreter to throw an error when it came to this code. Thank you all for your help!

Related