In my chrome extension, I'm using a v3 manifest. It starts a background script which starts the extension's page (extension.html) in the browser. The page also has a service script (extension.js) which handles things happening on that page. Extension.js is started from the last line of the HTML body. All of this seems to be working fine.
I've tried to encapsulate the complicated portions of the code into relevant function blocks (and seperate files), which are then called as functions from the main code stream. These functions get pulled into the background.js using importScripts('function.js'); - and this works great.
In the page's service script (extension.js), attempting to do the same importScripts('function.js'); results in Uncaught ReferenceError: importScripts is not defined,
Shouldn't this functionality work the same in both the background.js and extension.js scripts?
I've tried the various wrappers and permutations found in other similar questions. Since these are not really 'worker' scripts, those suggestions simply result in the importScript not being called.
Thanks!
Related
I have a website I'm designing for class, and the javascript/jquery works perfectly in a local directory and on firefox (for some reason), but doesn't on other browsers. I'm using Opera to test this site. When I use Inspect Element and look at the .js file, it shows up completely blank for some reason, even though its contents look fine from cPanel. There are no error messages to track down the issue either.
I transferred my files using ftp with FileZilla, and I'm using bluehost as a web hosting service. All my html files are in the public_html directory in cPanel, and my javascript file is in a subdirectory called _js. CSS files are loading fine, I've seen similar posts saying both js and css aren't working which isn't the case here.
This is my html. I also tried putting it before </body> without any more luck either. I've also tried using multiple srcs to Jquery libraries copied from other forum posts with similar questions, thinking maybe its a dependent library issue, but still nothing.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="_js/javascript.js"></script>
</head>
My javascript is set up as so
$(document).ready(function () {
I've tried putting this DOMContentLoaded before, after, and inside the document ready function.
document.addEventListener('DOMContentLoaded', init, false);
I'm at my wits end. I can't find anywhere else with this specific problem. I saw somewhere about how Firefox checks over the files multiple times, but I don't really understand how, nor do I know how to make other browser do it. I also don't know why the inspector just thinks its a blank js file. I didn't think hosting Javascript would be so tedious.
I am making some quick scripts to manipulate spreadsheets in my Google Drive. However I want to avoid the script accidentally running and modifying data before I know it works, or running additional times after it has done its job. Thus I would like to have a popup button/alert in the Google Script editor where the user (typically me) confirms that they want to continue running.
I have tried things such as getUi().alert(), but it seems to be more used when I distribute the script as an app. Any hints?
You cannot get alerts inside the Apps Script editor.
An option is that you add the debugger; statement in your code and then run the script in debug mode (Go to Run > Debug Function > function name).
The execution will automatically pause at places where the debugger statement exists.
I am visiting a website which I think has a bug. And I have tried running a javascript function (defined by them), after running the function the site works smoothly in that page. After I navigate to a different page, I again have to run the function. So I want it to run automatically after the page loads. I am using google chrome. So, are there any chrome extensions or any built in thing that can do this. Any help will be appreciated.
Thanks in advance.
I think tampermonkey is what you are looking for
https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo
Another solution is to write an extension that injects code in the page's context.
It's important, because normally code in the extension is isolated from the page.
Tampermonkey route is probably better though in your case.
I have a Chrome extension which is injecting some code into a web page (I know that part's working), which is trying to call a function that is part of the original web page. The function works fine from the console, but gives an error when the extension calls it. I assume this is some sort of security feature, but is there a way to get around it? Please help!
PS. It's just for one website, if that helps
You can't do it with content scripts. Chrome extensions content scripts live in isolated worlds, meaning they share DOM, but have separate JavaScript sandboxes. Read more here:
The workaround to this is to inject a <script> into the DOM of the page, but that code won't have privileges to call any chrome.* APIs.
So I'm debugging some code at work that I didn't write, and I'm having trouble understanding why in Firefox I have additional .js files loaded than I do in Chrome.
After scouring the code I can't seem to locate where these .js files are being included. I'm wondering if this is something Firebug can tell me or if another add-on or another method entirely can come to the rescue.
Thanks for your time.
Firefox can trigger a breakpoint on DOM manipulation (right-click on the node you're interested in) - if the scripts are being inserted while the page is running, you could break at the very start of the page loading and then set a DOM breakpoint on the parent tag of where the script is being inserted. Then, when the script tag is added, you'll get a break and a call stack.