TheBrusMeister / harviewer

Automatically exported from code.google.com/p/harviewer
0 stars 0 forks source link

Simple API for loading HAR files. #53

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Honza, I see in your documentation that there is way to get the viewer object 
(here: http://code.google.com/p/harviewer/wiki/API). My question is there a 
method there to feed the HAR itself possibly in the onViewerPreInit event ?

Original issue reported on code.google.com by phobouli...@gmail.com on 4 Jul 2011 at 4:01

GoogleCodeExporter commented 8 years ago
The difference between onViewerPreInit and onViewerInit is visible here:
http://code.google.com/p/harviewer/source/browse/trunk/webapp/scripts/harViewer.
js#149

The initialize method renders the content and loads HAR file if any is 
specified in the URL.

You should load any other HAR files within onViewerInit or specify them all in 
the URL.

Why do you want to load HAR log in onViewerPreInit?

Honza

Original comment by odva...@gmail.com on 4 Jul 2011 at 4:23

GoogleCodeExporter commented 8 years ago
The onViewerInit is fine indeed but what is the method to do so?

viewer.initialize({'log':...}) ?

I ll take a look at the code too.

I would like NOT to specify the HAR in the URL but feed it in the
HARviewer internally.

Original comment by phobouli...@gmail.com on 4 Jul 2011 at 4:46

GoogleCodeExporter commented 8 years ago
Ah, I see.

Take a look at HARModel.Loader.loadRemoteArchive
http://code.google.com/p/harviewer/source/browse/trunk/webapp/scripts/preview/ha
rModel.js#311

But I like the idea to have the method available directly on the viewer object. 
Something like:

viwer.loadHAR();

Let me know if you have any proposals.

Honza

Original comment by odva...@gmail.com on 4 Jul 2011 at 4:57

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
EDIT: Hmm yes... that would be perfect. Would that also work for the 
preview.php version of the HARViewer ?

Original comment by phobouli...@gmail.com on 4 Jul 2011 at 5:21

GoogleCodeExporter commented 8 years ago
Yes, the same method would be available on both. Both methods would be very 
simple and based on the Loader object, I guess.

Honza

Original comment by odva...@gmail.com on 4 Jul 2011 at 5:24

GoogleCodeExporter commented 8 years ago
Honza, I was also thinking that it would be nice if there was a method that 
would load a HAR file at any given moment. More specifically, to be called 
externally and regardless of any events triggered. Do you think that this is 
possible ?

Example:

Iframe loads preview.php with no path in URL. Seconds later an external AJAX 
call fetches a HAR file. A method in the global viewer object (globalized in an 
event) is called and the HAR file is fed into the viewer. 

Do you think that this would be possible ?

Original comment by phobouli...@gmail.com on 5 Jul 2011 at 7:29

GoogleCodeExporter commented 8 years ago
Patch committed at R324, available for both the viewer and preview.

> Do you think that this would be possible ?
yes, this should work

Selenium tests committed at R325

http://code.google.com/p/harviewer/source/browse/trunk/selenium/tests/testLoadHa
rAPIPreview.html

and

http://code.google.com/p/harviewer/source/browse/trunk/selenium/tests/testLoadHa
rAPIViewer.html

You can use these as examples (don't forget to set paths in 
selenium/tests/config.php

Here is another simplified example:

$("#content").bind("onPreviewInit", function(event)
{
    // Get application object
    var viewer = event.target.repObject;
    var settings = {jsonp: true};
    viewer.loadHar(<url>.harp", settings);
    viewer.loadHar(<url>.harp", settings);
    viewer.loadHar(<url>.har");
});

Here is a doc:
http://code.google.com/p/harviewer/source/browse/trunk/webapp/scripts/harViewer.
js#141

The order of loaded files is not preserved, but you can built on top of the 
callback functions.

Please try it and let me know if it works for you.

Thanks!

Honza

Original comment by odva...@gmail.com on 5 Jul 2011 at 9:46

GoogleCodeExporter commented 8 years ago
Excellent Honza! Great stuff indeed. 

Hmm.. I think I should have been more clear when I said "HAR file". I meant to 
say HAR object. So perhaps this would work just as well:

myhar = {'log':{...}}
viewer.loadHar(myhar);

What do you think ?

Original comment by phobouli...@gmail.com on 5 Jul 2011 at 10:18

GoogleCodeExporter commented 8 years ago
Hm..., in that case you should just call:

viewer.appendPreview(myHar);

Does it work for you?
Honza

Original comment by odva...@gmail.com on 5 Jul 2011 at 10:23

GoogleCodeExporter commented 8 years ago
Yeap thats perfect! Thanks Honza!

Original comment by phobouli...@gmail.com on 5 Jul 2011 at 10:58

GoogleCodeExporter commented 8 years ago
OK, cool.

Since the new API could be still useful for others. Could you please test it 
and let me know if it works for you?

Thanks!
Honza

Original comment by odva...@gmail.com on 5 Jul 2011 at 11:34

GoogleCodeExporter commented 8 years ago
Yeap will do!

Original comment by phobouli...@gmail.com on 5 Jul 2011 at 11:38

GoogleCodeExporter commented 8 years ago
Hey Honza,

I am having some trouble building. Look at this:

C:\harviewer\webapp\scripts>..\..\requirejs\build\build.bat app.build.js

C:\harviewer\webapp\scripts>set MYDIR=C:\harviewer\requirejs\build\

C:\harviewer\webapp\scripts>C:\harviewer\requirejs\build\..\bin\x.bat C:\harview
er\requirejs\build\build.js app.build.js

C:\harviewer\webapp\scripts>set MYDIR=C:\harviewer\requirejs\bin\

C:\harviewer\webapp\scripts>node C:\harviewer\requirejs\bin\x.js C:\harviewer\re
quirejs\bin\ C:\harviewer\requirejs\build\build.js app.build.js
cygwin warning:
  MS-DOS style path detected: /cygdrive/c/harviewer/webapp/scripts/C:\harviewer\
requirejs\bin\x.js
  Preferred POSIX equivalent is: /cygdrive/c/harviewer/webapp/scripts/C:/harview
er/requirejs/bin/x.js
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: Cannot find module '/cygdrive/c/harviewer/webapp/scripts/C:\harviewer\req
uirejs\bin\x.js'
    at Function._resolveFilename (module.js:322:11)
    at Function._load (module.js:267:25)
    at Array.<anonymous> (module.js:426:10)
    at EventEmitter._tickCallback (node.js:126:26)

I have cygwin but the path it mentions is not there.

BTW. I have tried to build the harviewer in linux and macos in the past with no 
luck. Windows however was easier.

I have no idea how nodejs works. Any clues?

I will check it again tomorrow.

Original comment by phobouli...@gmail.com on 5 Jul 2011 at 12:42

GoogleCodeExporter commented 8 years ago
Works for me (WindowsXP), I guess you didn't checkout all?

This seems to be the problem:
Error: Cannot find module '/cygdrive/c/harviewer/webapp/scripts/C:\harviewer\req
uirejs\bin\x.js'

Anyway, please report a new issue for this.

Honza

Original comment by odva...@gmail.com on 5 Jul 2011 at 12:57

GoogleCodeExporter commented 8 years ago
Done.

Original comment by phobouli...@gmail.com on 6 Jul 2011 at 7:27

GoogleCodeExporter commented 8 years ago
Great, I replied under that new bug.

Please let me know as soon as you try out the new APIs, I would like to update 
the doc.

Thanks!
Honza

Original comment by odva...@gmail.com on 6 Jul 2011 at 8:28

GoogleCodeExporter commented 8 years ago
Ok! Just tested the new API. Everything works as expected (JSONP and XHR).

Nice Honza! Thanks a lot!

Original comment by phobouli...@gmail.com on 7 Jul 2011 at 8:59

GoogleCodeExporter commented 8 years ago
Thanks, API doc updated:
http://code.google.com/p/harviewer/wiki/API

Honza

Original comment by odva...@gmail.com on 7 Jul 2011 at 12:57

GoogleCodeExporter commented 8 years ago
HAR Viewer 2.0.12 (including fix for this report) has been released 
http://www.softwareishard.com/har/viewer/

Honza

Original comment by odva...@gmail.com on 8 Jul 2011 at 3:12

GoogleCodeExporter commented 8 years ago
Nice! The "load har" functionality works nicely. We are already using this.

Just read the API wiki. No comments. Very concise.

Original comment by phobouli...@gmail.com on 8 Aug 2011 at 8:41

GoogleCodeExporter commented 8 years ago
Thanks for verification!
Honza

Original comment by odva...@gmail.com on 8 Aug 2011 at 10:19