I have a test where I go to Google.com and run the following commands in the console:
test = document.querySelector('#lst-ib') //#lst-ib is the ID of Google's search bar
test.value = 'abcd'
test.select()
window.getSelection().toString() //expected return value of 'abcd'
If I run this test in Chrome or Safari, I get the expected return value of 'abcd' - meaning the text in the input has been selected.
In FireFox, I get an empty string.
Does anyone have an explanation? I get the same behavior when I run this code on my own page from a script - not the console.
I'm testing on Firefox 54.01 and Chrome 59.0.3071.115
This is a known bug for Firefox. 16 years and counting.
https://bugzilla.mozilla.org/show_bug.cgi?id=85686
Related
This question already has answers here:
Weird behavior with objects & console.log [duplicate]
(2 answers)
Closed 2 years ago.
If i run the following code on chrome or firefox directly into the console, on the first log the value of value2 is 0 in the inlined representation, but if I expand the representation to check the whole object, it is showed as 17. Is this a multi browser bug or I am missing something with javascript here? The reason I am asking this question here is because this behaviour is happening across different browsers, which makes me think there is some kind of catch on the language or the function that I am not aware of.
Actual code:
action = new Object();
action.value1 = 17;
action.value2 = 0;
console.log(action);
action.value2 = action.value1;
console.log(action);
Tested on MacOS Catalina with the latest version of both browsers.
EDIT-----------------
The problem is the first console.log prints value2 being 0 but when I expand the object details it is showed as 17. I attached a print to clarify the question.
PRINT OF THE CONSOLE RESULTS
I would expect the result to be 0 on the value2 of the first output even with the expanded view.
console.log has different inner working between chrome, firefox, nodejs, and other javascript engine.
In your screenshot, the browser does 2 things:
prints the short preview of the action object
prints the expandable reference of the action object
The short preview is a readable version snapshot of the object at the time console.log is called
The expendable reference only prints an expand icon at the time console.log is called.
When expanded, chrome will fetch the CURRENT value the object referenced by that expendable reference and print it. It doesn't print the value when console.log is called
Since the value when the console.log is called ({value1: 17, value2: 0}), and the current value ({value1: 17, value2: 17}) is different, it prints different thing.
If you go to https://www.artistguitars.com.au on safari 12 ,open console and enter:
x='%str%';
x.replace (/%str%/g, '$15');
you will get '5' instead of $15
On other browsers it works well.
Why is that? I could not find information anywhere.
ctv.currentdate = new Date(ctv["current"]["#attributes"].attr);
Page works like a charm in Chrome but Firefox, IE10, & Safari all don't work. Firefox console returns the following message:
TypeError: ctv.current['#attributes'] is undefined
If I do console.log(ctv["current"]["#attributes"]);, Firefox returns undefined whereas Chrome returns an actual value, ie. Object {attr: "2013-7-28"}.
Ideas?
Chrome is supporting "#", but that's technically not allowed in ES5. Nice read: http://mathiasbynens.be/notes/javascript-identifiers
Cool validator (if you want to explore further): http://mothereff.in/js-variables
I have a JSON that contains values of "some thing" and "some/thing/other" as possible values that I want to write to:
$('li#'+fixRegion).append('<ul class="sub"/>');
I tried doing:
var fixRegion = region.replace(/\s/g,'');
fixRegion = fixRegion.replace(/\//g,'');
but it crashes firefox and I won't even bother to tell you want it does with firebug open. What horribly obvious thing am I doing wrong?
I have a Javascript application that relies on capturing keyboard events in a textarea. While testing and debugging it on Firefox (14.x) with firebug (1.10.2) I noticed that my application behaves differently when I have breakpoints active and the debugger is working.
I know how to detect Firebug but I would like to know if it is possible to detect (with Javascript) when the Firebug is actually used for debugging?
Edit: here is an example on some random site
This site catches the key event in an input box, prints out character code and replaces the pressed key with a text representation (ie. "enter" for enter key) or an uppercase (if a letter).
When I debug it with Chrome and place a breakpoint on the listener function, nothing happens when the breakpoint is reached (as expected), when I resume the script the text is printed out as normal.
When I debug it with Firebug on Firefox: Let us say that previously I pressed the "e" letter and the input bar contains text "E". I turn on the breakpoint and press letter "z". Firebug stops at the breakpoint but the input bar now has text "Ez" instead of "E". When I resume the script, this text is replaced with "Z" as expected.
I tried out another Firefox debugger (Venkman 0.9.89) and the same thing happened. So my guess is this is a Firefox problem, not the debugger problem. So the question might be more general, can it be detected when is the Javascript code being debugged?
This is what I do to detect Firebug:
if (window.console && (window.console.firebug || window.console.exception)) {
// At this point, Firebug is enabled
}
The first test is important to make sure that the console actually exists The second one will test for Firebug, although it will only work for older versions of it. The third one is there as Firebug adds the "exception" This is because the property "exception" is added by Firebug's plugin.
(Unrelated but interested: window.console.exception is the method used by Firebug to display a message onto the console. For example, type:
>>> window.console.exception("A message", {param:'Value'})
You will see an error that will look very familiar, with a dump of the passed object!
Merc.
Well, hope this answer will help someone.
Let function we debug to be such as:
function debugged()
{
debugger;
}
setTimeout(debugged, 3000);
add this debug detection code is:
setTimeout(this.x = function(a){ s = Math.abs(new Date() - a.c - 1000); a.c = new Date(); setTimeout(a.foo,1000, a); if(s>100)console.log("debug") },1000, {c: new Date(), foo:this.x})
so if we run it in some place and open debugger, it will trigger breakpoint and debug event will be catched(you can see it by "debug" word appearing in console). This is a concept, you may change detection period time and a way of raising debug flag. Thanks to single-threaded javascript.