Weastie
Weastie

Reputation: 157

How can one compare two web pages using just JavaScript?

I am using jsdom to emulate two different web pages, and I would like to compare the web pages to see if they are equal. It seems to me like it is impossible to get an exact test of whether or not the web pages are equal.

One thing I can do is compare each page's window.document.body.outerHTML to see if their HTML code is the same. However, this can not test, for example, that each page has the exact same events after pressing a button.

I can also do a deep comparison of each page's window element, to compare each page's global variables and their equality. But I can not test for local variables inside of a function.

The reason I am asking this is because I plan to emulate the exact same web page, but one time with some JavaScript code prepended, and check whether or not that JavaScript code caused any changes or not. The prepended JavaScript code is going to disable client-side access to document.cookie. The overall plan of the experiment is to test whether or not popular web pages will render differently without client-side JavaScript access to cookies.

Upvotes: 0

Views: 631

Answers (1)

Evert
Evert

Reputation: 99523

I think the direction you are thinking in is tests. You're right that the bytes emitted by the server is not going to tell you much about how they are interpreted.

There's many front-end test frameworks available. Write tests for your baseline, and then execute them on the version that has the cookie-related changes.

Upvotes: 1

Related Questions