IE10 has some wonderful enhancements in the HTML5 compliance area but remains a bear to develop JavaScript HTML5 when running on the WP8 as there is no way to debug the app except console messages.
Is there a remote debugging experience available for IE10 running on WP8 like the WebKit phone browsers have(see my video at http://www.youtube.com/watch?v=GNAjzFpNEj4 for example). When this is in place with a USB cable to desktop Safari debugging Javascript apps on IOS is easy as breakpoints can be set and variables examined in the remote debugger . I am hoping the same capabilities are in IE10 and would appreciate any information on where to enable these very much needed capabilities.
The bad news, that there is no new debug capabilities in comparison to WP7/IE9. Please take a look on How do I debug Internet Explorer on Windows Phone 7? since we are in exactly the same situation on WP8.
What I personally use on daily basis
Debug your app in IE10 Desktop as much as possible
Weinre remote debugger. Demo video. You can use the following app based on Weinre to simplify its usage (no local setup needed) - IeMobileDebugger src or link to Store
Supports
Html traversing
Html node styles, properties, metrics
Reading console output
Executing js on device side from console (including intellisense)
Dynamic script injection - ability to debug live sites
Not supported
js breakpoints
For javascript line by line debugging use aardwolf. Demo with VS integration.
To redirect console trace to Visual Studio output and be able to use console.log("some message") for tracing
index.html:
<script type="text/javascript">
window.console = {
log: function (str) { window.external.Notify(str); }
};
// output errors to console log
window.onerror = function (e) {
console.log("window.onerror ::" + JSON.stringify(e));
};
console.log("Installed console !");
</script>
MainPage.xaml.cs
private void Browser_Loaded(object sender, RoutedEventArgs e)
{
Browser.IsScriptEnabled = true;
// Add your URL here
Browser.Navigate(new Uri(MainUri, UriKind.Relative));
Browser.ScriptNotify += (s, arg) =>
{
Debug.WriteLine(arg.Value);
};
}
FWIW: Windows Phone 8.1 finally supports remote debugging. See http://blogs.msdn.com/b/visualstudioalm/archive/2014/04/04/diagnosing-mobile-website-issues-on-windows-phone-8-1-with-visual-studio.aspx
While not a full solution, Lauri Piispanen's consolelog.js, a nodejs-based remote JS console logger could help you.
Related
I hava a java program with two buttons, one for chrome and one for firefox. I press one of them, and the browser starts at some particualar location on the screen and with smalles size.
i have try running terminal commands, something like this
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Default" --app="data:text/html,<html><body><script>window.moveTo(198,60);window.resizeTo(1167,708);window.location='https://stackoverflow.com';</script></body></html>"
And it works, but only for chrome. I want at least chrome and firefox on both windows and linux.
Searching a little I have come across other solution. Running javascript on java, somethig like:
ScriptEngineManager factory = new ScriptEngineManager();
ScriptEngine engine = factory.getEngineByName("JavaScript");
engine.eval("window.open('https://stackoverflow.com')");
engine.eval("window.resizeTo(800,600)");
But Im getting compilation errors:
ReferenceError: "window" is not defined in <eval> at line number 1
And I don´t know whats going. Ideas?
For Windows, you can do something like this using Runtime:
Runtime rt = Runtime.getRuntime();
rt.exec("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe stackoverflow.com");
I believe that you can do something similar for Google Chrome. I took a look to a code I implemented in the past for Chrome and it was a little different, but previous approach should work as well:
Runtime rt = Runtime.getRuntime();
rt.exec(new String[]{"cmd", "/c","start chrome http://www.stackoverflow.com"});
If you would like to do it for a Linux based OS, then you can use Runtime as well:
Runtime rt = Runtime.getRuntime();
rt("/usr/bin/firefox -new-window http://www.stackoverflow.com");
I remember I got some references from this page:
https://www.mkyong.com/java/open-browser-in-java-windows-or-linux/
Hope it can help you.
ScriptEngineManager runs the script on server side. window is a client-side object, you can't access it from server.
in another word since you are not executing your script in a browser, the window object is not defined.
You can try this way to open a website on your default browser of the operating system:
Desktop desktop=Desktop.getDesktop();
URI url = new URI("http://somewhere");
desktop.browse(url);
to open a non-default browser in Java you should use Runtime.exec()
for Windows OS try this it worked for me:
String browserPath = "C:/Program Files/Mozilla Firefox/firefox.exe";
String url = "http://somewhere";
try {
String[] b = {browserPath, url};
Runtime.getRuntime().exec(b);
}
catch (Exception exc) {
exc.printStackTrace();
}
for further information on how to use Runtime.exec() on others OS read here
The main idea is to run a random page on Internet Explorer and get javascript errors and logs.
Is there a way to recover javascript console logs and execution error
from a random web page without accessing the F12 tool on Internet
Explorer?
I found that with Chrome based browser, you can get it on your AppData file log by adding --enable-logging --v=1 args when launching.
Any solution with any language are welcome.
Thank you for your answer.
NOTE :
random page on Internet Explorer means that I do not have the access on the source code.
Basic solution to this would be:
1. Use Exception Handling to catch the errors.
2. Log errors in a Global Array
3. Log the errors in a file using Blob and URL.createObjectURL. All recent browsers support this.
Have you considered using a Bookmarklet that:
Overrides window.console.log and window.console.error (to intercept messages)
Logs incoming messages somewhere using createObjectURL?
Or you could use something like firebuglite and auto-enable it like this:
<script type="text/javascript" src="https://getfirebug.com/firebug-lite.js">
{
overrideConsole: false,
startInNewWindow: true,
startOpened: true,
enableTrace: true
}
</script>
More instructions are here: http://getfirebug.com/firebuglite
If the F12 tool is not of your interest, then what about the Event Viewer? Open Event Viewer from Control Panel -> System and Security -> Administrative Tools -> Event Viewer. Then select the log Applications and Services Logs\Internet Explorer.
By default no events are being logged for Internet Explorer, to enable them create a new DWORD registry value named Feature_Enable_Compat_Logging under the following registry key:
HKCU\SOFTWARE\Microsoft\Windows\Internet Explorer\Main \FeatureControl
and set the registry value to 1.
Check the logs you get to see if it's what you're looking for.
One idea would be to write a browser extension which listens for window.onerror and writes to a file. Definitely not as elegant as the Chrome solution, but it would work fairly well.
Using local proxy might be a good one-time solution.
Charles web debugging proxy app has nice UI and it allows to replace any response with local resource.
So basically you'll need:
Download one any of the js files used on target page
add any code you wish to saved version
set up Charles to serve you your local version instead of remote one
You might try Fiddler. It's got its own logging and has amazing inspection power. It won't capture IE specific errors, since it's at a different layer, but it will definitely get you any code that's coming over the wire.
First of all: This is no duplicate of "how to automaticly convert a chrome extension"...
I wrote a complex chrome extension which is quite popular. So a lot of people asked me to publish a firefox - version.
I am currently in a quite early state of analyzing the difficulties I might run into. I am able to map most chrome-specific commands to others in firefox.
Just one topic is unsolved until now:
Chrome uses content-scripts and background-scripts.
the communication works that way:
Content-Script:
chrome.runtime.sendMessage(
{
Action: "LoadAll"
}, function(response)
{
mySetting= response.Setting;
}
);
background-script:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse)
{
if (request.Action === "LoadAll")
{
sendResponse({Setting: "hello out there!"});
return true;
}
)
});
(please ignore if I might have missed a bracket)
How is this communication been done on firefox extensions? Or does FF recommend a complete different approach?
If there is no "Take this command" - answer, a link to a more in-depth-explanation would be nice.
The thing you are looking for is Message Manager. We are developing a big and complicated extension for about 2 years for Fx and recently made a good Chrome port of it. Messaging process differs strongly in Fx and Chrome. Think of it like you inject a content script in window/browser/tab, which has few things in common with content scripts in Chrome, and then talk to your extension code from injected script via sendSyncMessage/sendAsyncMessage. I hope this helps.
I am getting script error in loading some web sites.
Please help me how to prevent script error in C# WebBrowser.
This is my code:
try
{
webBrowser1.Navigate(textBox1.Text);
while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
{
Application.DoEvents();
}
MessageBox.Show("Loaded");
}
catch(Exception)
{
MessageBox.Show("failed");
}
Write this in Your Code
webBrowser1.ScriptErrorsSuppressed = true;
To disable the script error pop up, you need to go to (in Internet Explorer) Tools->Internet Options, there go to the Advanced tab, and in Browsing select Disable Script Debugging (Other), but, the problem may be related to the fact that every site loaded in the WebBrowser control is rendered in IE7 compatibility mode, to solve this the only thing you can do is a registry hack like this: WebBrowser control to use IE9
change your registry to 2af8 which is IE 11 for devenv.exe
software/Microsoft/internet explorer/main/featurecontrol/feature_Browser_emulation
If your working with a GUI (like in Visual Studio) just go to the Webbrowser Properties and set "ScriptErrorsSuppressed" = true
It is easy to see how this error has been eliminated. But Visual Studio uses Internet Explorer and another Web Browser coding is hard. If you look at the versions, the last Visual Studio one uses IE 11 for WebBrowser tool.
The C++ GUI is recommended for one of each encoding:
https://msdn.microsoft.com/en-us/library/60k1461a.aspx
I want to execute a local program on my computer via Javascript in Chrome. In Firefox, it can be done as follows (after setting 'signed.applets.codebase_principal_support' to true in about:config):
function run_cmd(cmd, args) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var file = Components.classes["#mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(cmd);
var process = Components.classes["#mozilla.org/process/util;1"]
.createInstance(Components.interfaces.nsIProcess);
process.init(file);
process.run(false, args, args.length);
}
What's the equivalent code for Chrome?
This is not possible in Chrome without extensions.
This requires a NPAPI plugin in extensions, see http://code.google.com/chrome/extensions/npapi.html ,
I don't think you can. Chrome is very particular about such things, hence their sandbox
The preferred way to do this in Chrome is to use Native Messaging along with a Chrome extension. NPAPI is being phased out.
https://developer.chrome.com/extensions/nativeMessaging
Javascript has no capabilities to communicate externally outside of the browser. For instance, no disk input/output, no communication with the host OS such as Windows/Linux. Javascript is inherently tighter as it is executed by the browser itself.