Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging in the Windows Phone 7 Emulator browser?

I'm trying to test my homemade JavaScript framework in as many browsers as I can find. Today I realized that on my Windows computer, I could install the Windows Phone 7 developer tools and test in the emulator.

I did this, and sadly it does not work, but I have no idea how to tell what's going wrong. I don't have any idea how to try and fix it because in a framework, there are 1000 things that could go wrong, and all I have is to guess.

Does anyone know how to debug in the emulator browser, or am I just stuck?

like image 503
McKayla Avatar asked May 12 '11 01:05

McKayla


2 Answers

In order to debug my Javascript, from my Javascript I call:

window.external.notify("Some debug message");

I subscribe to the WebBrowser ScriptNotify event in my XAML, then in my C#:

private static void ScriptNotified(object sender, NotifyEventArgs e)
{
    Debug.WriteLine("Script notified: " + e.Value);
}
like image 180
Damian Avatar answered Oct 21 '22 10:10

Damian


This is perfect... I added the Script notifier to my MainPage.xaml.cs file with in the

public partial class MainPage : PhoneApplicationPage
    {

Section and it works like a charme.

I then found this snipit:

  // provide our own console if it does not exist, huge dev aid!
  if(typeof window.console == "undefined")
  {
  window.console = {log:function(str){window.external.Notify(str);}};
  }

      window.onerror=function(e, url, lineNumber)
      {
          console.log("ERROR! : " +url + "(" + lineNumber + ") : " + JSON.stringify(e));
      };

  console.log("Installed console ! ");

here: http://sim4all.com/blogging/?p=266.. PLEASE note that i have modified the onerror to include line nr and file referance.

this implements a Console.log object and a onerror Message.. It ie really helpfull..

This whole operation is of caurse only needed befor the Cordova layer is loaded.. Then Cordova takes better care of this.

Hope it helps.. Kim

like image 29
Kim Ras Avatar answered Oct 21 '22 09:10

Kim Ras