Search code examples
javascriptandroidhtmlperformancew3c

Run custom javascript code after loading any website


I am working on taking readings about web browser performance and so need to access the window.performance object of the browser. To collect this data i have written a javascript file, collect.js which i need to add to the DOM of the page that i need to test eg. www.google.com, www.facebook.com and so on...

Also i need to run this test for about 1000 websites, any manual approach is out of the question. I need it to be automated somehow.

How could i go about doing this?

EDIT: I need to run these tests on an android browser, so i need mobile oriented solutions.


Solution

  • You can create a simple android app with a WebView component. This way you can control which URLs are loaded and also insert your JS code.

    http://developer.android.com/guide/tutorials/views/hello-webview.html

    EDIT
    You can run any javascript like this:

    Implement a custom WebView:

    public class WebClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    
        @Override
        public void onPageFinished(WebView view, String url) {       
            // Execute your javascript below
            view.loadUrl("javascript:...");       
        }
    }