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

Array.from can be incorrectly defined by 3rd party js libs #1318

Closed
1 task done
eoghanmurray opened this issue Oct 2, 2023 · 2 comments
Closed
1 task done

Array.from can be incorrectly defined by 3rd party js libs #1318

eoghanmurray opened this issue Oct 2, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@eoghanmurray
Copy link
Contributor

eoghanmurray commented Oct 2, 2023

Preflight Checklist

  • I have searched the issue tracker for a bug report that matches the one I want to file, without success.

What package is this bug report for?

rrweb

Version

latest version with #1272 applied

Expected Behavior

inline styles recorded correctly

Actual Behavior

inline styles recorded as follows:

<style type="text/css">
[object CSSStyleRule][object CSSStyleRule][object CSSStyleRule][object CSSStyleRule][object CSSStyleRule][object CSSStyleRule][object CSSStyleRule][object CSSStyleRule][object CSSStyleRule ...
</style>

Steps to Reproduce

#1272 makes full use of the second map argument of the built in Array.from

I discovered today that MooTools < 1.6 implements their own version of Array.from, which lacks the second argument, so if an old version of mootools is on a website it messes things up — or also an old version of Prototype (e.g. 1.7.1)

I did a similar 'guard' for Date.now being overwritten in #1196
Is it a good idea to do the same in this case?

There might be small performance loss from an extra function, but main question would be whether it is our responsibility to patch over this sort of thing?

Here is a test to undo changes from 3rd party libraries:

	if (Array.from([1], (x)=>x*2)[0] !== 2) {
		// https://stackoverflow.com/a/8580576/6691
		const dummy_iframe = document.createElement("iframe");
		document.documentElement.appendChild(dummy_iframe);
		Array.from = dummy_iframe.contentWindow.Array.from;  // a clean working version
		//Array.prototype.from = dummy_iframe.contentWindow.Array.prototype.from;  // this is given in SO answer but doesn't work for some reason
		document.documentElement.removeChild(dummy_iframe);
	}

Testcase Gist URL

No response

Additional Information

No response

@eoghanmurray eoghanmurray added the bug Something isn't working label Oct 2, 2023
@billyvg
Copy link
Contributor

billyvg commented Jun 6, 2024

Just ran into this with a few customers, an alternative solution would be to not use the 2nd argument and explicitly call map()

@eoghanmurray
Copy link
Contributor Author

Actually I completely forgot I had this issue open, but suggested the same fix again which got merged with #1464 so this should no longer be an issue if you are using the latest code.
Open up a new issue or PR if 1464 doesn't fix things for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants