-2

I'm trying to load a script on LinkedIn through an extension. However, it looks like it is using AJAX to render the main container every time you click on one of the links in the header.

I have this, which does not work:

$(function() {
  console.log("LOADED");
  $(window).on("load", () => {
    $(window).on("hashchange", function(e) {
      console.log("PATH CHANGED") // I want to print this every time the route changes and scrape the updated DOM
    });
  });
});

It makes sense since it's not using hashes. I don't know how to add a listener to path changes + scrape the updated dom.

Is there a way to do this?

bigpotato
  • 26,262
  • 56
  • 178
  • 334

1 Answers1

-1

The change of the URL in the browser without reload is done by history.pushstate

 history.pushState({id: 'SOME ID'}, '', "http://thisisthenewURL.com/whateva");

you can listen to this event by using the following code:

 window.onpopstate = function (event) {
  // do stuff here
 }

This has been answered in the following post: How to detect when history.pushState and history.replaceState are used?

Edwin Krause
  • 1,766
  • 1
  • 16
  • 33