NoamGaash / playwright-advanced-har

MIT License
26 stars 0 forks source link

When using a customMatcher, the HAR request postData stored in _file is not loading. #20

Closed TinoChen105 closed 3 months ago

TinoChen105 commented 3 months ago

If a request is stored in HAR and only utilizes postData._file for storage, it cannot be accessed when using a customMatcher.

For example:

A HAR file:

  "log": {
    "entries": [
      {
        "request": {
          "method": "POST",
          "url": "https://dev-cb-patch-monitor.quid.com/cb/api/2/runSearches",
          "headers": [],
          "queryString": [],
          "postData": {
            "mimeType": "application/x-www-form-urlencoded",
            "text": "",
            "params": [],
            "_file": "80cfc9ca2ceb7ebb0da70500393558554ef433da.dat"
          }

80cfc9ca2ceb7ebb0da70500393558554ef433da.dat : product=%22SEARCH%22&searchInfo=false

When using customMatcher:

matcher: (request, entry) => {
            entry.request.postData.params; // This is null
                        entry.request.postData.text; // This is null
        },

How to access entry's postData? When recording the HAR, only certain requests are saved to _file without any information in text or params. The workaround for this is to use updateContent: 'embed' to avoid it.

NoamGaash commented 3 months ago

Thanks @TinoChen105 ! I made a test demonstrating the issue https://github.com/NoamGaash/playwright-advanced-har/pull/21 And now we can do test-driven-development and fix it.

However, there's a performance tradeoff. If we'll read the content of all of the entries before calling the compare functions, it will hurt performance.

Maybe we should export the parseContent function instead? This way, the developer will have control over when they want the file content to be parsed

TinoChen105 commented 3 months ago

Thanks! Sounds good to me.

NoamGaash commented 3 months ago

Great! I made a little fix to allow the matcher to be async. Would you like to be a code reviewer for this PR? #21