I'm working on a chrome extension that uses the Bootstrap Collapse (v2.3.2) functionality on dynamically created elements by attaching event listeners at render time. I'm running into a problem where usage of collapse on the parent page no longer works when I load my extension. I tested this on bootstrap's documentation and was able to reproduce. The collapse stops functioning in the example while my extension functions correctly. I figure there must be some pollution of the global jQuery object when I load my version of bootstrap.js.
This is the script portion of my manifest:
"content_scripts": [{
"run_at": "document_start",
"matches": ["<all_urls>"],
"js": [
"js/vendor/jquery-min.js",
"js/vendor/bootstrap.min.js",
"js/content_script.js",
]
}]
And inside js/content_script.js
// #render
function render () {
$elInIframe.find('.accordion-toggle').on('click', function() {
var targetName = $(this).attr('data-target');
var target = $elInIframe.find(targetName);
target.collapse('toggle');
});
}
The lifecycle of my extension is:
- Load content_script (uses jquery and bootstrap loaded by extension as content_scripts).
- Initialize and inject iframe.
- Get data asyncronously and inject as HTML inside the iframe
- call render, attaching click listeners to the element in the iframe
So to clarify, my extension works as expected, but I'm breaking pages that also utilize bootstrap.js.
As a possible solution I tried moving bootstrap.js to a web_accessible_resource and loading it in the template. However, after doing so, calling target.collapse
results in an error (not a function) as the jquery used by my extension isn't modified by loading bootstrap.js -- and I'm not even sure bootstrap is loading correctly in the iframe by the extension.