Disabling Chrome Console Developers Tools - javascript

I tried disabling the console but it didnt work in my chrome for some reason.
How does Facebook disable the browser's integrated Developer Tools?
Code
$(document).ready(function(){
with ((console && console._commandLineAPI) || {}) {
(function() {
try {
var $_console$$ = console;
Object.defineProperty(window, "console", {
get: function() {
if ($_console$$._commandLineAPI)
throw "Sorry, for security reasons, the script console is deactivated on netflix.com";
return $_console$$
},
set: function($val$$) {
$_console$$ = $val$$
}
})
} catch ($ignore$$) {
}
})();
}
});
function abs(){
return "Hey Its not Working";
}
When i run abs() from console it shows me output Hey Its not Working which means its not disabled. So am i doing something wrong ?

Google repaired the console so that it is no longer possible to disable it in that way.
Note that Facebook does still add a warning message to the console, but you can still freely run arbitrary code there.
At this time there is no mechanism to prevent someone from using the Developer Tools to... well, develop stuff.

Related

Listen(capture) an iframe console logs

I'm trying to catch console logs of an iframe which I don't have access to its source and its implementation.
<iframe src="an http address" name="my-iframe" allowFullScreen/>
When the iframe logs data I see them in my console. But the problem is,
this piece of code
// define a new console
var console = (function(oldCons){
return {
log: function(text){
oldCons.log(text);
if(text === "hi"){
alert("text")
}
},
info: function (text) {
oldCons.info(text);
if(text === "hi"){
alert("text")
}
},
warn: function (text) {
oldCons.warn(text);
if(text === "hi"){
alert("text")
}
},
error: function (text) {
oldCons.error(text);
if(text === "hi"){
alert("text")
}
}
};
}(window.console));
//Then redefine the old console
window.console = console;
Which I got from this post is not working for the iframe logs. It only works on my app console logs.
If the src is a different domain, and you can't run code directly on the other domain (for example, by being able to modify or insert a .js into it), then there's nothing you can do. This is for security reasons: browsers don't want to leak any information between domains unless the sender of the information deliberately allows it.
If you can alter code on the other domain, you could monkeypatch the console and have it pass the log information to the parent window with postMessage so that the parent can do something with it.
If you happen to be trying to examine messages for your personal use only (rather than for use by random people on the internet), you can modify your browser to run your custom JavaScript on the other domain with a userscript, by using a userscript manager like Tampermonkey.

Tag inserted by the browser Brave before the head tag

i found a tag before the head tag on my webpage, inserted by the Brave browser.
my question would the following run on my page if my content Content-Security-Policy doesn't allow run script's that doesn't have a valid nonce or integrity attribute.
second question, the script asks to disable (disableDappDetectionInsertion)???
third what does this script do? this script has a attribute of "data-dapp-detection".
it occurs after the window is blured for a while.
no erros in the brave console either.
Brave Version 1.10.97 Chromium: 83.0.4103.116 (Official Build) (64-bit)
(function() {
let alreadyInsertedMetaTag = false
function __insertDappDetected() {
if (!alreadyInsertedMetaTag) {
const meta = document.createElement('meta')
meta.name = 'dapp-detected'
document.head.appendChild(meta)
alreadyInsertedMetaTag = true
}
}
if (window.hasOwnProperty('web3')) {
// Note a closure can't be used for this var because some sites like
// www.wnyc.org do a second script execution via eval for some reason.
window.__disableDappDetectionInsertion = true
// Likely oldWeb3 is undefined and it has a property only because
// we defined it. Some sites like wnyc.org are evaling all scripts
// that exist again, so this is protection against multiple calls.
if (window.web3 === undefined) {
return
}
__insertDappDetected()
} else {
var oldWeb3 = window.web3
Object.defineProperty(window, 'web3', {
configurable: true,
set: function (val) {
if (!window.__disableDappDetectionInsertion)
__insertDappDetected()
oldWeb3 = val
},
get: function () {
if (!window.__disableDappDetectionInsertion)
__insertDappDetected()
return oldWeb3
}
})
}
})()
Install the brave browser and go to this site to see what your CSP policy will allow or not. https://content-security-policy.com/browser-test/
As for the dapp-detection this site goes into more detail:
https://www.howtogeek.com/449046/what-is-the-brave-browser-and-how-does-it-compare-to-chrome/
But in a nutshell... Brave uses BAT (Basic Attention Tokens) and comes with an ad blocker already installed (Brave Shields). BAT is based off the Etherium Blockchain and is their way of allowing ads and monetization while also respecting users privacy.

Listen to browser console events and errors

Looking for a way to log on my server all console events shown on my visitor's browser console.
Not just what I'm firing with console.log, but everything...
Is there a way?
Yes you can just override console method like
var logFn = console.log;
console.log = function(arg1) {
// do your work on log information
logFn('your console hacked')
}
console.error = function(arg1) {
// do your work on error part
logFn('your console hacked')
}
you will find on console only one message 'your console hacked' you can customize according to you.

window.localstorage failing on IOS safari, out of incognito mode

Localstorage stopped working after the last iOS update on all our IOS devices, yet we can't seem to find any reference online to that change, and wondering what's going on.
I have a jsfiddle implementing basic localstorage setting and getting.
It runs without issue on Chrome (IOS) but fail entirely on Safari:
https://jsfiddle.net/mva3ap87/
Here is the code:
var ls = {
set: function() {
if (window.localStorage && window.localStorage.setItem) {
window.localStorage.setItem('hello','world');
return true;
}
return false;
},
get: function() {
if (window.localStorage && window.localStorage.getItem) {
return window.localStorage.getItem('hello');
} else {
return 'nope';
}
}
}
$('.status1').html(window.localStorage?'Yes':'No');
$('.status2').html(ls.set()?'Success':'Failure');
$('.status3').html(ls.get());
This issue affect all the IOS devices we have tried.
Incognito mode is not on.
No popup blocker active."Do not track" is off.
Cookies are allowed (but shouldn't matter anyway).
Any clue what's going on?
Update:
I was able to borrow a mac and found the error:
"DOM Exception 22: An attempt was made to add something to storage that exceeed the quota".
The localstorage is empty, and the browser is not in incognito mode.
I'm even more confused.

Javascript Console.log Not working in Chrome, or Firefox

I am doing a very simple:
console.log("Testing");
along with :
alert("testing");
The Alert works (so I know the javascript is working) but I'm unable to see the log. When I use Firefox I get the following error:
The Web Console logging API (console.log, console.info,
console.warn, console.error) has been disabled by a script on this
page.
What is going on? I have looked at the following topics, but none have helped:
Chrome: console.log, console.debug are not working
console.log quit working in Chrome
Console.log not working in Chrome [closed]
why does console.log not output in chrome?
Console.log not working at all
I have also made sure that the funnel is working and that logging is turned on.
What else could the problem be?
I just came across this problem after a Firefox update and managed to fix it. Here's the code that caused the problem:
/* IE fix that allows me to still log elsewhere */
if (typeof(console)=="undefined") {
var console = {
output: null,
log: function (str) {
// we can't emulate the console in IE, but we can cache what's output
// so that IE users can get it via console.output
if (!this.output) this.output = new Array();
this.output.push(new String(str));
}
};
window.console = console;
}
In the previous version of FireFox, "var console;" wouldn't get executed. Now it seems to have added some sort of branching/prediction mechanism. Seeing that I may define a variable called console with global scope, it disables window.console.
I fixed this issue by renaming var console; to var cons;
/* IE fix that allows me to still log elsewhere */
if (typeof(console)=="undefined") {
var cons = {
output: null,
log: function (str) {
// we can't emulate the console in IE, but we can cache what's output
// so that IE users can get it via console.output
if (!this.output) this.output = new Array();
this.output.push(new String(str));
}
};
window.console = cons;
}
I still need to test this to make sure it does what I expect in IE, though. I just need to find a copy of IE without a console (I think 9 or below).
I just wish that Firefox would tell you what line of what script disabled the console - that would be nice.
I had the same issue with a Magento e-commerce site (version 1.6.2.0).
I fixed it commenting the following lines in /js/varien/js.js:637
if (!("console" in window) || !("firebug" in console))
{
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i)
window.console[names[i]] = function() {}
}
This fix is only (obviously) for Magento sites.
Turns out the theme developer had added firebug lite to the theme without me knowing. Turning it off fixed the problem.
I think the page you are viewing when trying to log via console.log() has a script in it which overwrites the property window.console.log. Usually this property is preset with a function by the browser but you a script may override it.
First suggestion: Do you use any other dev tools that use console? On Firefox I had the same problem with Firebug running on background without me noticing it, after closing firebug the error went away. Here's a possiple duplicate thread: Firefox Web Console Disabled?
Second, if it is overridden by some script, then one by one disable scripts and see which draws the error.

Categories

Resources