Firefox add-on devtools logs don't show object keys/values - firefox

I'm currently developing a Firefox add-on and I noticed some logging issues in the add-on devtools (for the background script) page. Whenever I'm trying to console.log some object, I don't see any keys or values of this object in the console. There's also no way to "expand" the object like I can in the "regular" (not for an add-on) Firefox browser console.
So, if I e.g. open the add-on devtools and type console.log({ test: "test" }), I only do get "Object { }" as an output:
If I try to log an error I do get a similar result (I can e.g. still log err.message):
try {
throw new Error("");
} catch (err) {
console.log(err);
}
Since I'm currently developing the add-on locally, I'm using web-ext to launch and watch the add-on. web-ext run is essentially launching Firefox without any profile which I thought may explain the difference compared to a regular Firefox browser console.
However, even if I load the add-on in my normal Firefox profile (load temporary add-on), I do see the same behavior for any add-on devtools console.
Is there any setting in the Firefox (add-on) console (or in my preferences) that I can use to log the whole object like it does in the normal Firefox console, e.g. if I open devtools for a regular webpage:

It's hard to tell what's going on without seeing the relevant code for your Firefox add-on, but I have a hunch that this is happening because of reference changes in your script.
In Javascript, an object is actually a reference to a location in memory. So when you run console.log(obj), and that object is modified before you access the console, then it may show up as empty (i.e. because the value being referenced has changed).
I would make sure that the object that you are trying to log is not modified after you log it. If there are any other objects based on the one that you are trying to log, changes to them may also cause your initial object to change as well.
You can try JSON encoding to get around this for logging purposes:
console.log(JSON.parse(JSON.stringify(obj)));
If that's not the issue, then perhaps there's some weird async behavior going on. In that case, you can try logging the object at several other points in your code to see exactly where this behavior starts.

Related

Selenium cannot find elements on Google service while minimalised or headless mode

I try to create a program which will automate fetching data from one of the Google services. By using chrome and watir (which is basically a Ruby library build on top of the Selenium). Everything works fine as long as I keep my browser open. But when I minimize window, my program is not even able to pass a login process since it cannot find certain elements. This is my code to login:
#browser = Watir::Browser.new :chrome, options: { detach: true }
#browser.goto BASE_URL
#browser.text_field(name: 'identifier').set USER_EMAIL
#browser.element(xpath: '//*[#id="identifierNext"]').click
#browser.text_field(xpath: '//input[#type="password"]').set USER_PASSWORD
#browser.element(xpath: '//*[#id="passwordNext"]/div/button/div[2]').click
When my browser is minimize, during attempt to set a password I get this error message:
*** Watir::Exception::UnknownObjectException Exception: element located, but timed out after 30 seconds, waiting for
#<Watir::TextField: located: true; {:xpath=>"//input[#type="password"]", :tag_name=>"input"}> to be
present
And it works just fine as an open window. Even if I maximize the window during whole process program is suddenly able to locate missing input fields. The same story goes in many other points further. Program is not able to locate some elements unless chrome window is open.
Needless to say it works even worse in headless mode and I'm basically not able to locate any of those elements in html code.
As far as I understand Google services frontend side are build with Angular framework which inject html code dynamically. But shouldn't selenium pretend to act like a regular user and trigger the same responses on minimized and open window (and the headless mode as well)?
Is is some kind of blockade from Google to prevent this kind of automated proces and how can I bypass it?
Is this an issue with Chrome and switching for e.g. Firefox would fix it?
Can I implement some additional actions to actually mimic human interaction and pretend that my Chrome window is open?

Chrome DevTools Protocol addScriptToEvaluateOnNewDocument using ruby chrome_remote

So I am trying to inject a script to run on any page using addScriptToEvaluateOnNewDocument on chrome 79, but it doesn't seem to be working.
I am using the ruby gem chrome_remote, which gives a pretty basic access to the CDP.
Here is an example ruby:
scpt =<<EOF
window.THIS_WAS_SET = 1
EOF
ChromeRemote.client.send_cmd 'Page.addScriptToEvaluateOnNewDocument',{source: scpt}
ChromeRemote.client.send_cmd "Page.navigate", url: "http://localhost:4567/test"
I then start chrome with --remote-debugging-port=9222
The Page.addScriptToEvaluateOnNewDocument will always return {"identifier"=>"1"} (even if I call it multiple times, say with different scripts).
And when I open console on the opened tab in Chrome (which works, so I know CDP in general is working), and check the value of window.THIS_WAS_SET, it is undefined.
Is there any way to verify the command was sent to the browser, such as a log in the browser it was received? Any way to see what scripts were injected? Why does each call always return a ScriptIdentifier of 1, that seems problematic?
Anyone have a similar example working?
you should call "page.enable" first.

Firefox seems to fail on registering a ServiceWorker for Push Notifications?

Firefox seems to fail on registering a ServiceWorker for Push Notifications, with an error "InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable", but the code works in Chrome and Edge, and appears to be compliant with the examples online and the spec.
I've thrown an example up on one of my test sites, https://wiegandtech.net/ - visiting it in Chrome will prompt for permission and then opt-in successfully, sending the info to the server. But Firefox prompts, doesn't complete the registration, and doesn't fire any error or throw anything into the console. When I try to debug, it seems to never return from navigator.serviceWorker.ready.then call - I debug in and reg is undefined, even though the promise says it shouldn't be. I can find no reason why this is failing. I do see in Fiddler that FF gets the worker file, so it appears to be starting the call, but never finishing? The worker is valid JavaScript, as far as I can tell. Does anyone have any documentation on how Firefox's implementation is different from Chrome's/the spec?
Firefox requires the ServiceWorker's URL to end in .js - I was using an ASP.Net site and returning javascript but through my own controller. When I just give it the URL for the .js file itself, it now works. Would file a bug, but too non-trivial to setup a site given that ServiceWorkers require a real life site to troubleshoot, and their source code doesn't appear to be on github.

Prevent browser-sync log data in firebug console

I often use gulp and its plugin browser-sync.
Every time i open firebug console tab, i see its full of logs like :
GET http://localhost:3000/browser-sync/socket.io/?EIO=3&transport=polling&t=1457523519574-0 200 OK ۳ms browser...11.1.js (line 2)
I can use clear button but logs are interminable! they will appear twice.is there any persistent way to ride of these(browser-sync) logs?
Yes, there is. Just uncheck the option Show XMLHttpRequests within the Console panel's options menu.
Though note that this will disable the logging for all XMLHttpRequests, (aka AJAX requests).
There is currently no way to filter out specific logs. There are already two enhancements requests for that: issue 4507 and issue 6835 targetting Firebug 2, but as Firebug 3 will be built upon the DevTools, it is probably wiser to follow the DevTools related requests. The closest one to your issue is bug 905978 to filter out messages for blackboxed sources, but I've also filed bug 1102797 some time ago for allowing to blackbox sources from within the Console panel and bug 1255311 right now for ignoring specific log messages.

clear up GM_log from error console

Is there a way to clear up GM_log messages from error console from userscripts on a certain event?
I don't want to clear up manually. On trigger of certain event, want to clear up the old log from the error console and show up the new log.
You cannot clear the error console. If you could, evil websites could clear it too and erase the record of their misdeeds.
You should no longer use GM_Log() anyway. Use Firebug and the excellent console logging functions it provides.
Then you can use console.clear().
Note, to avoid conflicts with Firefox's newish console functions, and to ensure that the output appears in Firebug's console, you may need to prefix the calls with unsafeWindow.
So your script could do something like this:
unsafeWindow.console.clear ();
unsafeWindow.console.time ('ScriptRun');
unsafeWindow.console.log ("Script start." );
unsafeWindow.console.timeEnd ('ScriptRun');
Which would look like this in the Firebug console:
-- with all the preceding cruft erased. (Anything the webpage does after the clear() call will still appear though.)

Resources