Skip to content

Commit be2786e

Browse files
committed
just use URL class
1 parent 592c9c3 commit be2786e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/wombat.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -922,22 +922,31 @@ Wombat.prototype.getFinalUrl = function(useRel, mod, url) {
922922
};
923923

924924
/**
925-
* Converts the supplied relative URL to an absolute URL using an A tag
925+
* Converts the supplied relative URL to an absolute URL using URL class
926926
* @param {string} url
927927
* @param {?Document} doc
928928
* @return {string}
929929
*/
930930
Wombat.prototype.resolveRelUrl = function(url, doc) {
931-
var docObj = this.$wbwindow.document;
932-
if (doc) {
933-
var baseURI = doc.baseURI;
934-
if (baseURI.startsWith(this.HTTPS_PREFIX) || baseURI.startsWith(this.HTTP_PREFIX)) {
935-
docObj = doc;
931+
var wombat = this;
932+
933+
function isValidBaseURI(doc) {
934+
if (!doc || !doc.baseURI) {
935+
return false;
936936
}
937+
return (doc.baseURI.startsWith(wombat.HTTPS_PREFIX) || doc.baseURI.startsWith(wombat.HTTP_PREFIX));
938+
}
939+
940+
var baseURI = null;
941+
if (isValidBaseURI(doc)) {
942+
baseURI = doc.baseURI;
943+
} else if (isValidBaseURI(this.$wbwindow.document)) {
944+
baseURI = this.$wbwindow.document.baseURI;
945+
} else {
946+
baseURI = this.$wbwindow.__WB_replay_top.document.baseURI;
937947
}
938-
var parser = this.makeParser(docObj.baseURI, docObj);
939948

940-
return new this.URL(url, parser).href;
949+
return new this.URL(url, baseURI).href;
941950
};
942951

943952
/**

0 commit comments

Comments
 (0)