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

Fix error with blob urls #840

Merged
merged 3 commits into from
Dec 23, 2020
Merged

Fix error with blob urls #840

merged 3 commits into from
Dec 23, 2020

Conversation

gmetais
Copy link
Contributor

@gmetais gmetais commented Dec 22, 2020

When a page contains a blob url (this is quite rare) such as <img src="blob:http://localhost:8888/99335797-0bf4-46db-bd23-14ed9a1c5549">, there's an error inside requestMonitor.js:

(node:7074) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: resp.timing is empty when handling blob:http://localhost:8888/99335797-0bf4-46db-bd23-14ed9a1c5549
    at /phantomas/core/modules/requestsMonitor/requestsMonitor.js:235:9
    at /phantomas/lib/AwaitEventEmitter.js:15:19
    at Array.forEach (<anonymous>)
    at AwaitEventEmitter.emit (/phantomas/lib/AwaitEventEmitter.js:13:31)
    at Object.onRequestLoaded (/phantomas/lib/browser.js:220:17)
    at /phantomas/lib/browser.js:226:10
    at /phantomas/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:62
    at Array.map (<anonymous>)
    at Object.emit (/phantomas/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:43)
    at CDPSession.emit (/phantomas/node_modules/puppeteer/lib/cjs/puppeteer/common/EventEmitter.js:72:22)

Here is an example HTML page to test with:

<head>
<script>
// From https://gist.github.com/nolanlawson/0eac306e4dac2114c752
function fixBinary (bin) {
    var length = bin.length;
    var buf = new ArrayBuffer(length);
    var arr = new Uint8Array(buf);
    for (var i = 0; i < length; i++) {
        arr[i] = bin.charCodeAt(i);
    }
    return buf;
}

var base64 = 
    "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAB1klEQVR42n2TzytEURTHv3e8N1joRhZG" + 
    "zJsoCjsLhcw0jClKWbHwY2GnLGUlIfIP2IjyY2djZTHSMJNQSilFNkz24z0/Ms2MrnvfvMu8mcfZvPvu" + 
    "Pfdzz/mecwgKLNYKb0cFEgXbRvwV2s2HuWazCbzKA5LvNecDXayBjv9NL7tEpSNgbYzQ5kZmAlSXgsGG" + 
    "XmS+MjhKxDHgC+quyaPKQtoPYMQPOh5U9H6tBxF+Icy/aolqAqLP5wjWd5r/Ip3YXVILrF4ZRYAxDhCO" + 
    "J/yCwiMI+/xgjOEzmzIhAio04GeGayIXjQ0wGoAuQ5cmIjh8jNo0GF78QwNhpyvV1O9tdxSSR6PLl51F" + 
    "nIK3uQ4JJQME4sCxCIRxQbMwPNSjqaobsfskm9l4Ky6jvCzWEnDKU1ayQPe5BbN64vYJ2vwO7CIeLIi3" + 
    "ciYAoby0M4oNYBrXgdgAbC/MhGCRhyhCZwrcEz1Ib3KKO7f+2I4iFvoVmIxHigGiZHhPIb0bL1bQApFS" + 
    "9U/AC0ulSXrrhMotka/lQy0Ic08FDeIiAmDvA2HX01W05TopS2j2/H4T6FBVbj4YgV5+AecyLk+Ctvms" + 
    "QWK8WZZ+Hdf7QGu7fobMuZHyq1DoJLvUqQrfM966EU/qYGwAAAAASUVORK5CYII=";

var binary = fixBinary(atob(base64));
var blob = new Blob([binary], {type: "image/png"});
var url = URL.createObjectURL(blob);
var img = new Image();

img.onload = function() {
    URL.revokeObjectURL(this.src);
    document.body.appendChild(this);
}

img.src = url;
</script>
</head>
<body></body>

This fix prevents phantomas from trying to analyze the request as a network request.

@macbre macbre added the bug label Dec 22, 2020
@macbre macbre added this to the v2.1 milestone Dec 22, 2020
@macbre
Copy link
Owner

macbre commented Dec 23, 2020

@gmetais - thanks for a fix! Can you add a test case, please? The one from PR description looks fine.

@gmetais
Copy link
Contributor Author

gmetais commented Dec 23, 2020

I've tried to add a test, but it won't fail. The error is just visible in the logs when debug is activated, it has no impact on stats. A silent bug!

@macbre macbre merged commit 597b2d2 into macbre:devel Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants