Patterns for balancing processing between content scripts and background scripts - google-chrome-extension

I'm developing a chrome plugin that changes the content of some pages. Taking a look at a extension that does something similar (https://github.com/callumlocke/json-formatter). I saw that the plugin uses the backgound script to do the heavy lifting and content script to take care of less intensive tasks and it delegates the hard work (via message passing) to background scripts. Is this a pattern? Should I avoid havy processing tasks on content scripts and create a background script for that?

It's not a pattern but it's kind of common sense. As background scripts runs in a different context, if the extension is doing heavy work and it eventually crashes, then the current page won't be affected.
Also, you'll get the chance to use the devtools profiler and other devtools features to analyze your extension. This is pretty cool since you'll be able to know what's dragging your extension performance if that is the case.
In brief, it's a great idea to move all the heavy processes to background and use content scripts only to deal with DOM manipulation.

Related

How to measure performance of browser extension on websites (> 100)

I'm looking for tools for measuring webpage performance with certain browser(Chrome) extension installed. I would like to know things like # of requests, time to first byte, slowest call, average call, FCP, and LCP et. al..
I've used development tool that comes with the browser and extensions such as Page load time, Performance-Analyser.
I'm look for some method/tool that can load pages one by one from a list and be able to download the results, so I can test many webpages and batch process the results.
Thanks.
You can use any suitable browser automation framework i.e. Selenium which is some form a de-facto standard
Check out 6 Easy Steps to Testing Your Chrome Extension With Selenium for example
There is also Lighthouse tool which can also be considered and executed from shell scripts or programmatically, however it's more web-oriented hence not all metrics will be applicable so you might get a lot of false-negative results.

How to pass arguments to a program from a web page?

I'll be the first to admit that my programming experience and skill in web services is practically non-existent. I usually program things that run completely isolated or locally, with either C or assembly. I'm proficient enough to get a website going, with some basic authentication and directory read access on the system. That's about it.
I'm trying to do a project that's well outside of my comfort zone and get some experience in controlling stuff remotely/via web. Using a Raspberry Pi running Debian, I'm running a program on it in C that takes in information such as video and UART data, does some crunching and triggers some outputs and writes events to a file/folder. This component is fairly straightforward to get running automatically. Getting a webserver up so a remote user can look at the files and pictures the driver program creates is also extremely easy.
The problem for me comes in trying to make a GUI on a webpage that can be used to manually control these outputs. I'm going to need some scripting to handle the button presses on the web page, clearly, but is there a scripting language in particular that stands out for using kernel objects/system calls so I can actually talk to that process? I figure the best way is to use message queues, but I don't know if Python or PHP (or another scripting language) are capable of doing this, and if there are any that are better at this than others. What is the preferred way of doing this?
I know it's possible since we've all seen those kitten-cams with the flash container where you can move the camera or trigger things. I just have no idea where to start.
Thanks for any help
Java can call native commands via JNI (http://en.wikipedia.org/wiki/Java_Native_Interface) from within a JVM. So if you already have C code that can handle the controls, it's just a matter of getting Java code to call them.
As for the scripts to handle button presses, there are several options. One way is to do it asynchronously via AJAX (which requires some JavaScript knowledge) or the other is by doing the traditional page refresh on each press. Sorry to be a bit vague on the answer, but this requires a lengthy explanation of how the whole JSP (Java Server Pages)/Servlets eco system works.
Here's a good place to start:
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/

Kiosk program (web browser), deployment struggles

Okay, here's a complicated one I've been breaking my head over all week.
I'm creating a self service system, which allows people to identify themselves by barcode or by smartcard, and then perform an arbitrary action. I run a Tomcat application container locally on each machine to serve up the pages and connect to external resources that are required. It also allows me to serve webpages which I then can use to display content on the screen.
I chose HTML as a display technology because it gives a lot of freedom as to how things could look. The program also involves a lot of Javascript to interact with the customer and hardware (through a RESTful API). I picked Javascript because it's a natural complement to HTML and is supported by all modern browsers.
Currently this system is being tested at a number of sites, and everything seems to work okay. I'm running it in Chrome's kiosk mode. Which serves me well, but there are a number of downsides. Here is where the problems start. ;-)
First of all I am petrified that Chrome's auto-update will eventually break my Javascript code. Secondly, I run a small Chrome plugin to read smartcard numbers, and every time the workstation is shutdown incorrectly Chrome's user profile becomes corrupted and the extension needs to be set up again. I could easily fix the first issue by turning off auto-update but it complicates my installation procedure.
Actually, having to install any browser complicates my installation procedure.
I did consider using internet explorer because it's basically everywhere, but with the three dominant versions out there I'm not sure if it's a good approach. My Javascript is quite complex and making it work on older versions will be a pain. Not even mentioning having to write an ActiveX component for my smartcards.
This is why I set out to make a small browser wrapper that runs in full screen, and can read smartcard numbers. This also has downsides. I use Qt: Qt's QtWebkit weighs a hefty 10MB, and it adds another number of dependencies to my application.
It really feels like I have to pick from three options that all have downsides. It really is something I should have investigated before I wrote the entire program. I guess it is a lesson learnt well.
On to the questions:
Is there a pain free way out of this situation? (probably not)
Is there a browser I can depend on without adding tens of megabytes to my project?
Is there another alternative you could suggest?
If you do not see another way out, which option would you pick?

Stress/Load Test Ajax heavy Web Application

I am looking to simulate heavy load on my web server by constantly visiting a list of urls over and over and over again!
Initially, I planned to write a simple script using wget/curl but because the site uses a lot of ajax requests for much of its heavy lifting, this isn't a feasible options. It would require me to write a complicated script to parse the html from the link, extract the ajax request, curl them. I would have to do this recursively for each request.
Ideally there is some way to get a broswer (or something similar) to just loop through a list of urls spending 15-30 seconds on each link before moving on! This would mean all my javascript will be executed when each url is visited and the sites load will be representative
Anyone know how i can do this easily?
Take a look at LoadBooster(https://www.loadbooster.com). It is a cloud-based load testing service which utilizes headless scriptable browser PhantomJS to test web sites. Disclaimer: I work for LoadBooster.
What you're looking for is "load testing software". There are a lot of solutions - how well they handle AJAX varies greatly. A tool that drives a real browser (via something like Selenium) might be the easiest for you to get started with - assuming your test scenarios are really as simple as "visit this list of URLs". There is at least one real-browser web-based testing tool that can do this for you (BrowserMob). Our product, Web Performance Load Tester, simulates the browser but we are generally able to handle AJAX pretty well. AFAIK, all of the free solutions are pretty limited in what they can do - particularly when AJAX is involved.
Use apache bench.
ab
Something simple like this:
> ab -k -n 100 -c 100 -g myresults.txt http://myajax.com/page
The above would mean, 100 pages over 100 concurrent connections, all with keep alive, and save the results to the text file myresults.txt.
http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=ab+apache
There is also seige.
I used WebLOAD for a similar type of test - it's correlation engine is very useful in heavy AJAX situations.

How to extract random screenshots from a swf file? In Linux

I need to automatically extract some random screenshots from Flash content (swf) in linux.
I will appreciate any advice on this.
Thanks in advance.
I don't think this is going to be easy, a guess at a possible implementation may be
Run a virtual X server such as Xvfb (this is easy)
Write a program which encapsulates the flash plugin, either by using a browser (for example Mozilla / xulrunner) or implementing the plugin interface directly and invoking the necessary logic. The Netscape plugin interface is documented.
Have some way of waiting for the SWF to fully load, including all sub-components; I don't know how easy it is to tell, as there may not be callbacks for this.
Wait until the flash has got to an interesting section (You may use some arbitrary criteria for this, either just time-based or content based)
Stop the flash (possibly just by suspending the thread etc), and snapshot the window / screen you're using.
If you've got a Xvfb server you can use whatever resolution you want and use the whole screen.

Resources