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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions core/modules/requestsMonitor/requestsMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,17 @@ function parseEntryUrl(entry) {
// asset type
entry.type = "other";

if (entry.url.indexOf("data:") !== 0) {
// @see https://nodejs.org/api/url.html#url_class_url
if (entry.url.indexOf("data:") === 0) {
// base64 encoded data
entry.domain = false;
entry.protocol = false;
entry.isBase64 = true;
} else if (entry.url.indexOf("blob:") === 0) {
// blob image or video
entry.domain = false;
entry.protocol = false;
entry.isBlob = true;
} else {
parsed = new URL(entry.url) || {};

entry.protocol = parsed.protocol.replace(":", ""); // e.g. "http:"
Expand All @@ -40,11 +49,6 @@ function parseEntryUrl(entry) {
if (entry.protocol === "https") {
entry.isSSL = true;
}
} else {
// base64 encoded data
entry.domain = false;
entry.protocol = false;
entry.isBase64 = true;
}

return entry;
Expand Down Expand Up @@ -230,7 +234,7 @@ module.exports = function (phantomas) {
*
* "Throughout this work, time is measured in milliseconds"
*/
if (!entry.isBase64) {
if (!entry.isBase64 && !entry.isBlob) {
// resp.timing is empty when handling data:image/gif;base64,R0lGODlhAQABAIABAAAAAP///yH5BAEAAAEALAAAAAABAAEAQAICTAEAOw%3D%3D
assert(
typeof resp.timing !== "undefined",
Expand Down Expand Up @@ -325,7 +329,7 @@ module.exports = function (phantomas) {
}

// requests stats
if (!entry.isBase64) {
if (!entry.isBase64 && !entry.isBlob) {
phantomas.incrMetric("requests");
phantomas.addOffender("requests", {
url: entry.url,
Expand Down Expand Up @@ -353,6 +357,8 @@ module.exports = function (phantomas) {

if (entry.isBase64) {
phantomas.emit("base64recv", entry, resp); // @desc base64-encoded "response" has been received
} else if (entry.isBlob) {
// Do nothing
} else {
phantomas.log(
"recv: HTTP %d <%s> [%s]",
Expand Down