webrecorder / wombat

Wombat.js client-side rewriting library
GNU Affero General Public License v3.0
81 stars 30 forks source link

Wombat proxy error: hasOwnProperty function is called, leading to an error. #132

Closed ARiedijk closed 7 months ago

ARiedijk commented 8 months ago

This error is due to the implementation of the Wombat.prototype.overrideDataSet function. In this function, a JavaScript Proxy object is utilized to override the .dataset attribute of an element. The problem surfaces when the function wombat.startsWithOneOf assumes that the input is a string and attempts to call the indexOf method. However, in certain scenarios, the input is not a string, which leads to the following error message:

TypeError: t.indexOf is not a function
    at f.startsWithOneOf (wombat.js:1:17613)
    at Object.get (wombat.js:1:47412)
    at readData (dataset_hasownproperty.js:35:16)
    at dataset_hasownproperty.js:53:9
    at NodeList.forEach (<anonymous>)
    at doCheck (dataset_hasownproperty.js:52:12)

A solution to this problem involves adding a check to confirm that target[prop] is a string before calling the startsWithOneOf function. This could be implemented with the following code:

var result = target[prop];

if (typeof result === 'string' && wombat.startsWithOneOf(result, wombat.wb_prefixes)) {
    return wombat.extractOriginalURL(result);
}

This solution prevents the error by first verifying if result is indeed a string before invoking the startsWithOneOf method. This way, it avoids the error message in cases where result is not a string.

hasOwnPropertyIssue.zip

ikreymer commented 7 months ago

Thanks for identifying an adding a simple repro case! Will be fixed in next release (3.7.1)