问题
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.
回答1:
You can create a simple android app with a WebView
component. This way you can control which URL
s 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:...");
}
}
回答2:
If you are looking for an automated solution, try PhantomJs this provides an automated headless web browser. Also has access to network traffic
回答3:
perhaps you can try "bookmarklet" http://www.bookmarklets.com/
the advantage over greasemonkey script is that it can run on firefox and explorer
来源:https://stackoverflow.com/questions/9634409/run-custom-javascript-code-after-loading-any-website