How to get CPU usage in javascript [duplicate] - javascript

I noticed this today in my Chrome.
Google Meet is showing a chart of CPU usage in their "Troubleshooting" panel. I'm wondering if there's an existing API for this or is it a clever trick I'm not aware of.

I was curious about this as well when I saw the CPU Usage graph on the Troubleshooting page on the Google Meet's page. So googled a lot and I couldn't find any proper answer as to how it is being achieved apart from this link: https://developer.chrome.com/extensions/system_cpu#method-getInfo.
So, I went through the minified source code of the Google Meet's site and it turns out Google Meet is using this but not on their webpage directly, because it is for chrome extensions only, but through the Google Hangouts Extension which is present in Chrome, Brave and the new Microsoft Edge (Chromium-based).
The chrome extension is calling the chrome.system.cpu API to get the information about the processor, core count, temperatures, etc., and these details are being passed to the Google Meets page via window.postMessage API and Message Passing between Chrome Extension and a Webpage.
This is a neat little way to achieve this if you are the creator of the browser :P.

Most probably, they are using Chrome specific API since this will not work on other browsers.
The closest thing that I've found is https://developer.chrome.com/extensions/system_cpu#method-getInfo
Below is a screenshot from Firefox stating that this will work only on Chrome.

Related

Open web console in javascript

Is it possible to open the client's web console in javascript (CTRL+SHIFT+K on Firefox)? Define the size, the position, else?
Thank you
I haven't heard of this being possible, and I couldn't find anything in a recent search about how to do it either. I did find another stackoverflow conversation about something similar here: Can I programmatically open the devtools from a Google Chrome extension?
From that, I surmise that if it's not possible from a browser extension, it seems even less likely to be possible from plain JavaScript.

Google maps javascript api bug android browser (Jelly bean and prior)

So, this question concerns only the old android browser (before chrome became the standard browser) and the google maps javascript api v3.
I am developing a website, together with an app with a webview, showing (parts of) that website.
Lately, the google map windows that are included in the website have stopped working properly. The map shows up, but any touch event on the map, like dragging the map to show other locations, as well as two finger zoom are not working anymore. the error that is shown in the javascript console (on every touch event on the map) is:
Uncaught TypeError: Illegal constructor -- From line 125 of http://maps.googleapis.com/maps-api-v3/api/js/26/2/intl/nl_ALL/common.js
After a days of looking for bugs in my code it seems to me that this could be a bug in the google maps javascript api. The error occurs not only on my website, but on all embedded google maps that i could find. Even in google's own api documentation.
The error only occurs in the old standard android browser, but old android versions are still in use quite commonly, and i cannot tell my users to switch to another browser because it has to work in a webview as well.
I could reliably reproduce this issue on a samsung xcover 2 (gt-s7710, android 4.1.2) and an api 17 simulator (android 4.2) in this link: https://developers.google.com/maps/documentation/javascript/
Has anyone else encountered this problem and/or found a workaround?
EDIT:
I filed a bug report to google that got accepted, so in the meantime i guess Dvy Hrnsch's workaround is the best solution!
i had the same problem as you described.
Explanation:
At least i found a simple workaround (after hours of headache).
I just found out, that Google Maps Javascript API has 3 API References.
The "Experimental Version", "Release Version" and the "Frozen Version".
If you include the API without specifying the exact version, it will use the "Experimental Version" by default.
As i noticed, this version (3.26) got an Update on 30. of August 2016 which seems to cause the bug.
SOLUTION:
Just change your API from:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=API-KEY&libraries=geometry,places"></script>
to
src="http://maps.google.com/maps/api/js?v=3&key=API-KEY&libraries=geometry,places"
Now its using the "Release Version" (last change on 17. of August 2016) of the API.
Source: https://developers.google.com/maps/documentation/javascript/versions
For me it works now on Android 4.3 (API Level 18) with cordova.
I hope this helps you also.
Best wishes
Got almost crazy before I found Dvy Hrnsch's answer. I want to add some information that could be useful in this matter:
Android applications using WebView 534.30 and maybe older (being part of Android 4.3 and older) fail to give Google Maps its full functionality if the v=3 parameter is missing. Although the charts are being displayed correctly and zooming in and out by pressing [+] and [-] is possible pushing the chart or using the click event is not possible.
With newer Android versions (that use WebView 537.36 or younger) these problems don't occur.
Tom

Automatically run JavaScript code upon loading a specific website

I've written scripts to filter out threads and posts in a programming forum by author.
But you need to post the code into the web console for each page individually.
I was wondering if it were possible and if so how (using either firefox or chrome), to set your browser up to run a specific script upon loading a specific site? Is it possible as an extension or plugin?
You can use Tampermonkey for Google Chrome
Tampermonkey is the most popular userscript manager for Google Chrome.
Greasemonkey for Firefox:
Allows you to customize the way a web page displays or behaves, by using small bits of JavaScript.
You can use dotjs.
dotjs is a Google Chrome extension that executes JavaScript files in ~/.js based on their filename.
If you navigate to http://www.google.com/, dotjs will execute ~/.js/google.com.js.
This makes it super easy to spruce up your favorite pages using JavaScript.

How to make a form-filling google chrome extension

I was wondering if anyone could provide me with some links to some tutorials or explain (with some example code), how I would go about making a simple google chrome extension (or in any programming language or browser if that is impossible), how I would make an extension that can visit a specific site, fill a login form on that site, click some links and then do the same sort of thing on the linked to site.
Thanks
Personally, I would not use a chrome extension, but maybe a perl script. There is an extension called WWW::Mechanize that is designed exactly to do this kind of stuff.
You can find plenty of tutorials and examples, just google it.
Edit in 2021: the above recommendation has become a bit outdated since 2013. For a more up-to-date take, I'd still recommend a scriptable headless browser instead of an extension for most automation tasks, but probably not WWW:Mechanize. There are good lists of options, such as this one.

Is greasemonkey a built-in extension of Google's Chrome?

I'm trying both greasemonkey and Google's Chrome extensions. And found that Chrome seems to be using the same API names as GM. (I seem to be having the same bug...)
Just wondering whether greasemonkey is already a Google Chrome extension?
Yes, I believe you can just add Greasemonkey scripts and Chrome installs them as an 'extension' like all the other native extensions.
Checkout this article:
http://lifehacker.com/5461675/chrome-4-supports-greasemonkey-userscripts-without-an-extension
Note, however that some scripts seem to be supported on GreaseMonkey for Firefox only and can be a little buggy in Chrome. I'm not sure of the exact differences in implementation.
Simon.
#Simon pretty much hit it, but I wanted to make sure that this point is super-clear.
Google Chrome supports Greasemonkey scripts natively, using the same API so as to make existing scripts compatible. There's no Greasemonkey extension required.
Yes, Chrome supports userscripts but not fully as Greasemonkey. For example check out this userscript
Docs Online Viewer: http://userscripts.org/scripts/show/127774
It works well with Greasemonkey (in Firefox) but not with Chrome natively. There are many Greasemonkey functions that Chrome does not support yet.
I copy and paste a post from GreaseMonkey:
There is no greasemonkey extension for google chrome. What actually happened is chromium (the project which google chrome is based) developed it's own extension system and one component of that extension mechanism (probably inspired heavily by greasemonkey in the first place) works in almost exactly the same way (an external javascript interacting with a page purely through it's DOM) as greasemonkey. The chromium system uses a completely different api but effectively does the same thing. This large overlap in purpose and functionality combined with the popularity of greasemonkey on firefox meant they decided to implement the greasemonkey api (the majority of it anyway) natively within chromium. From there they went one step further and had the browser automatically wrap any greasemonkey scripts inside a chromium extension automatically and effectively made greasemonkey scripts a first class citizen.

Categories