New Firefox version console.log problems [duplicate] - javascript

This question already has answers here:
Firefox Web Console Disabled?
(4 answers)
Closed 8 years ago.
I have Firefox 28.0 running on Mac OSX and am trying to use the console and Firebug.
I have javascript that calls console.log to test values of variables and the progress of
post and get requests.
The error message I am getting is:
The Web Console logging API (console.log, console.info, console.warn, console.error) has been disabled by a script on this page.
the code that makes the call:
if(e.target.id == "RL")
{
console.log('reloading..')
location.replace('../dummy.php');
//return false;
}
(dummy.php is a script that calls header('location:') which redirects back to the requesting page, for the sake
of reloading.)
so what is doing the disabling?

Firebug is disabling the built-in console and replacing it with its own console.

Related

Why am I getting a CORS error from just a simple Settimeout function in javascript? [duplicate]

This question already has answers here:
javascript modules and CORS
(4 answers)
Closed 10 months ago.
Everything is working fine in Chrome the problem is with FireFox and Microsoft Edge. With these two browsers I keep on getting CORS errors. I am making no API calls in this website. All this function that is causing this error is doing is resetting the opacity of some text I hid back to 1.
This is the function that is causing the error:
setTimeout(() => {
opacityP.style.opacity = 1;
opacityB.style.opacity = 1;
}, 3000);
This are the error message from FireFox and Microsoft Edge:
Thanks in advance for your help.
I think it's not possible to access local script files at the browser level.
You can run the code through a local server like localhost:3000 or so.
Xampp or Wamp would work for you.
If you're using VS Code, you can use their extension.
https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer
Hope this helps you!

Why is requestBody returning undefined in chrome extension? [duplicate]

This question already has answers here:
Chrome extension to read HTTP response
(2 answers)
Chrome Extension - How to get HTTP Response Body?
(5 answers)
Closed 11 months ago.
When I run my code, it first logs the URL of the network request then when I try logging the body, it just says undefined. When I click on the URL link that is logged in the console from the first console.log, it downloads the js file onto my PC that I am trying to print. Is there something wrong with my requestBody or is there another way of printing the content of the js file into the console without having to open it?
//background.js
function logURL(requestDetails) {
if (requestDetails.url.includes("getMe"))
{
console.log(requestDetails.url)
console.log(requestDetails.requestBody)
}
}
chrome.webRequest.onBeforeRequest.addListener(
logURL,
{urls: ["<all_urls>"]},
['requestBody']
);

Hide 401 console.error in chrome dev tools getting 401 on fetch() call [duplicate]

This question already has answers here:
Suppress Chrome 'Failed to load resource' messages in console
(3 answers)
Closed 5 years ago.
I have some code where i make a fetch call. This takes advantage of window.fetch api built into modern chrome / firefox.
The code sometimes hits a 401:unauthorized response. This is normal and I want it ignored, which I can do with the flow of the code. However, Chrome does show an unsightly console.error message when I try to run it.
How can I PROGRAMMATICALLY prevent this console error from showing in the dev console on all machines (i.e., no chrome dev filters or tampermonkey type plugins).
here's a sample to work off of:
fetch("http://httpstat.us/401", {requiredStatus: 'ok'})
.then(function() {
console.log("pass!");
}).catch(function() {
console.log("fail!");
});
Unfortunately, this cannot be done, as this type of message in the console is printed by chrome itself. Repressing this type of message has been debated for years, but the consensus seems to be that this message is desirable - see this discussion.
Just in case you're interested: As per this comment, the reason we're seeing this message is because the response to resource retrieval requests is evaluated, and messages are dispatched at the context level.
Essentially, the way chrome was written does not allow us to change this effect, and thus we have the error messages.

console.log not working in chrome.runtime.onMessage.addListener [duplicate]

This question already has answers here:
Accessing console and devtools of extension's background.js
(9 answers)
Closed 7 years ago.
Google Chrome Extension.
The console.log doesn't work in the addListener, however works fine outside addListener. I have reinstalled. I have tried this on Windows and MacOS.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log("listen"); // this does not
alert("got here"); // this works
}
);
If the code is in your background this console.log doesn't appear in the log of the current page. Look like that is the case.
If that is the case:
Go to chrome://extensions/ look for your extension.
Click on Inspect views: background.html (you can have another name depending of you manifest). You will see a developer tool with the a console.

Chrome Extensions - onRequest/sendRequest vs onMessage/sendMessage [duplicate]

This question already has answers here:
Chrome Extension: Port error: Could not establish connection. Receiving end does not exist.
(2 answers)
Closed 9 years ago.
Checking out this sample extension linked by a page in the Chrome Extension center, I see they used
chrome.extension.onRequest.addListener(onRequest);
in the background.js page in order to listen to the contentscript.js and
chrome.extension.sendRequest({}, function(response) {});
in the contentscript.js in order to talk to the background.js page.
But I can't find the documentation for these functions anywhere in the web and Google's Message Passing guide only mentions
chrome.extension.sendMessage(...)
to send, and
chrome.extension.onMessage.addListener(...)
to listen.
Which functions should I use? Is sendRequest/onRequest obsolete? Is the Google's dev guide still up-to-date?
It seems sendMessage is favored over sendRequest, which is to be deprecated: http://codereview.chromium.org/9965005/
Also note the change in API path from
chrome.extension.onRequest
chrome.extension.sendRequest
to
chrome.runtime.onMessage
chrome.runtime.sendMessage
will save you getting frustrated over why e.g. chrome.extension.onMessage is not working!

Categories

Resources