ayakashi
Version:
The next generation web scraping framework
22 lines (21 loc) • 953 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function default_1() {
["height", "width"].forEach(property => {
// store the existing descriptor
const imageDescriptor = Object.getOwnPropertyDescriptor(HTMLImageElement.prototype, property);
// redefine the property with a patched descriptor
Object.defineProperty(HTMLImageElement.prototype, property, Object.assign(Object.assign({}, imageDescriptor), { get: function () {
// return an arbitrary non-zero dimension if the image failed to load
//tslint:disable
if (this.complete && this.naturalHeight == 0) {
return 16;
}
//tslint:enable
// otherwise, return the actual dimension
//@ts-ignore
return imageDescriptor.get.apply(this);
} }));
});
}
exports.default = default_1;