Listening to URL change on Twitch.tv

Rickkwa

When you browse all games on Twitch and you click on a game, it gets the content dynamically without reloading the page. The url also changes from https://www.twitch.tv/directory to https://www.twitch.tv/directory/game/GameNameHere. How can I listen to this url change?

I tried using window.onpopstate in the following code (in a TamperMonkey script) but the event doesn't fire.

$(document).ready(function() {
    console.log("Running"); // works

    window.onpopstate = function(e) {
        console.log("onpopstate triggered");
    };
});

Edit: Upon further investigation, it seems that for TamperMonkey, I had to use unsafeWindow instead of window to get onpopstate to work. However, onpopstate only works for when the browser goes back or forward. Please refer to the accepted answer for the other cases.

Todd Christensen

See here: How to get notified about changes of the history via history.pushState?

Basically, you'll want to intercept calls to pushState and replaceState. If you can't do that, you can (ugly) use a setInterval to monitor the URL for changes.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Listening to URL change on Twitch.tv

From Dev

Twitch TV JSON API Issue

From Dev

Downloading the first frame of a twitch.tv stream

From Dev

XMLHttprequest not working the twitch.tv api

From Dev

Twitch.tv does not work, Lubuntu 16.04

From Dev

Twitch.tv API Online/Offline Not Accurate

From Dev

Twitch API, Stream URL

From Dev

Golang - Parsing JSON string arrays from Twitch TV RESTful service

From Dev

Extract Twitch ursername from url

From Dev

listening for checkbox change

From Dev

angular - Listening on transcluded change

From Dev

Twitch API - reading url with json in Java

From Dev

Extract Id from Twitch Clip URL

From Dev

React native change listening port

From Dev

Playing Twitch.Tv Video within Android App? (Android Studio development)

From Dev

How can I wrap a bootstrap row with an href element that's produced from twitch.tv's API?

From Dev

Change tomcat listening port using sed

From Dev

How to change listening port on webbserver IIS 7?

From Dev

How do I change the RDP listening port?

From Dev

Backbone view listening to model, not firing on change or reset?

From Dev

change mysql listening (bind) address on windows

From Dev

Listening to change of context path in apache tomcat 7

From Dev

There was no endpoint listening at (url) that could accept the message

From Dev

Android TV Play Video from URL

From Dev

Directives are not listening for $watch when I change any select

From Dev

Cannot change Kestrel listening port from command line

From Dev

Broadcast receiver listening for connectivity change firing at random intervals

From Dev

how to change java listening interface from localhost to IP address?

From Dev

jQuery Button function listening to menu open/close state change state

Related Related

  1. 1

    Listening to URL change on Twitch.tv

  2. 2

    Twitch TV JSON API Issue

  3. 3

    Downloading the first frame of a twitch.tv stream

  4. 4

    XMLHttprequest not working the twitch.tv api

  5. 5

    Twitch.tv does not work, Lubuntu 16.04

  6. 6

    Twitch.tv API Online/Offline Not Accurate

  7. 7

    Twitch API, Stream URL

  8. 8

    Golang - Parsing JSON string arrays from Twitch TV RESTful service

  9. 9

    Extract Twitch ursername from url

  10. 10

    listening for checkbox change

  11. 11

    angular - Listening on transcluded change

  12. 12

    Twitch API - reading url with json in Java

  13. 13

    Extract Id from Twitch Clip URL

  14. 14

    React native change listening port

  15. 15

    Playing Twitch.Tv Video within Android App? (Android Studio development)

  16. 16

    How can I wrap a bootstrap row with an href element that's produced from twitch.tv's API?

  17. 17

    Change tomcat listening port using sed

  18. 18

    How to change listening port on webbserver IIS 7?

  19. 19

    How do I change the RDP listening port?

  20. 20

    Backbone view listening to model, not firing on change or reset?

  21. 21

    change mysql listening (bind) address on windows

  22. 22

    Listening to change of context path in apache tomcat 7

  23. 23

    There was no endpoint listening at (url) that could accept the message

  24. 24

    Android TV Play Video from URL

  25. 25

    Directives are not listening for $watch when I change any select

  26. 26

    Cannot change Kestrel listening port from command line

  27. 27

    Broadcast receiver listening for connectivity change firing at random intervals

  28. 28

    how to change java listening interface from localhost to IP address?

  29. 29

    jQuery Button function listening to menu open/close state change state

HotTag

Archive