Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'ReferenceError: HAR is not defined' in new webextension based plugin. #24

Open
farooqrahman opened this issue Aug 10, 2018 · 3 comments

Comments

@farooqrahman
Copy link

Hi @janodvarko,

We successfully launched our product using har-export-triggerExport-0.6.1 and it's been used by our customers. All credit goes to you for providing this super cool new plugin which uses new WebExtension.
But one of our customer's face this issue 'ReferenceError: HAR is not defined'.
The environment in which this error reported is
Firefox version: 61.0
har_export_trigger version: 0.6.1

All the HAR dump process happens during selenium java execution. We dump the HAR after every click action on the page.
This dumping of the HAR happens instantly after button click. In one of the customer application page when the user clicks on a button we got this error. But if I delay the dumping of HAR say after 2 or 3 seconds then this error does not occur.
Is there any event listener which we have used in the previous version of har-export-triggerExport-0.5.0-beta.7, where we specify the below code before dumping of HAR so that we can wait for the event before dumping of the HAR.

if (typeof HAR === 'undefined') {
   addEventListener('har-api-ready', triggerExport, false);
}else { 
   triggerExport();
}

This is a very high priority bug for us can you please address this issue and give us a workaround.

Regards,
Farooq.

@leipreachan
Copy link

leipreachan commented Aug 13, 2018

@farooqrahman you might want to add these preferences to your session initalize flow:

{ 
            args : [
                '-devtools',
            ],
            prefs: [
                'devtools.netmonitor.persistlog': true,
                'devtools.toolbox.selectedTool': 'netmonitor',
                'devtools.toolbox.footer.height': 0,
            ]
}

@xmhubj
Copy link

xmhubj commented Aug 14, 2018

You may need retry mechanism on your code side to work around this...at this moment. If the HAR API is not defined, wait for couple of seconds, then try it again.

Another possible way could be adding waitForPageLoad command after each click command on a button, then dump HAR after waitForPageLoad command. This can make sure HAR API can be injected before you are trying to call it

I guess that HAR is not defined error indicates that the DOM is not ready, while your code is trying to call HAR api to dump HAR. At that time, HAR API object may not be injected yet.

Good luck!

@farooqrahman
Copy link
Author

@leipreachan I am already using those options when dumping the HAR. Thanks for the suggestions.

@xmhubj yes, you are right somehow we need to wait for the page load to happen so that HAR object can be injected. I found one solution for this which fixes this problem. I check whether HAR object is available or not before dumping the HAR. Below is the pseudocode
if HAR object available then
use the HAR object
else
poll for the HAR object availability and use it once available.

Below is the javascript code I have used for this issue. Here I am polling for every 500ms to check the HAR object availability.

if (typeof HAR != \"undefined\" ) { dumpHAR(); }
else { var interval = setInterval(function() { 
                         if(typeof HAR != \"undefined\") { 
                             clearInterval(interval); dumpHAR();"
                           } 
                      }, 500);"
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants