machawk1 / Mink

Chrome extension that uses Memento to indicate that a page a user is viewing on the live web has an archived copy and to give the user access to the copy
MIT License
49 stars 3 forks source link

Going from twitter page to tweet does not reset the # of mementos operation #59

Open phonedude opened 10 years ago

phonedude commented 10 years ago
  1. start at: https://twitter.com/WebSciDL

it shows 3 mementos

  1. click on a tweet, such as:

https://twitter.com/phonedude_mln/status/504381080460611584

and the 3 mementos display doesn't change. it's like it doesn't recognize that a new page has been loaded

I haven't been able to duplicate this on other sites but it happens when navigating within twitter.

machawk1 commented 10 years ago

Twitter may be changing the URI without actually "loading" a new page in the traditional sense but instead relying on an Ajax query to get the new content.

http://stackoverflow.com/questions/824349/modify-the-url-without-reloading-the-page

machawk1 commented 10 years ago

More info on manipulating the state of the browser without reloading using HTML5 and JS: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

machawk1 commented 10 years ago

Getting closer. I can detect the change in URI from the history manipulation but unless I call the native push state function, this breaks Twitter's rewriting methods.

    var pushState = history.pushState;
    html = "var nativePushState = window.history.pushState; window.history.pushState = function(a,b,c) { alert(a); alert(b); alert(c);nativePushState(a,b,c);};";

    var headID = document.getElementsByTagName("head")[0];         
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.innerHTML = html;
    headID.appendChild(newScript);
machawk1 commented 10 years ago

A better solution, but the browser complains about an illegal invocation.

the content script:

var headID = document.getElementsByTagName("head")[0];         
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.src = chrome.extension.getURL('script.js');
headID.appendChild(newScript);

script.js:

(function(){
var nativePushState = window.history.pushState;
window.history.pushState = function(a,b,c) {
    // Do something
    console.log('foo');
    nativePushState(a,b,c); //Continue by calling native history.pushState
};
})()
machawk1 commented 10 years ago

Maybe better, chrome now has a native implementation of this for extensions to use: https://developer.chrome.com/extensions/webNavigation

machawk1 commented 10 years ago

Verified as occurring on Facebook.com as well.

machawk1 commented 9 years ago

The reason this is not captured is due to the webrequest handlers' filter being limited to main_frame, which prevents requests for things other than the main page (e.g., images) from going through the same negotiation logic as the main page. The following code, when isolated into a separate bare-bones extension, was able to detect when a tweet was selected on the main page. The trick is to filter on the Ajax request type and not the main page but in the Mink implementation, this has to be done intelligently so as to not be invoked on every page on the web, simply the ones that 'change the URI programmatically'.

chrome.webRequest.onCompleted.addListener(function(deets){
    console.log("onHeadersReceived()");
    console.log(deets.url);
},
{urls: ["<all_urls>"],types: ["xmlhttprequest"]},["responseHeaders"]);
machawk1 commented 8 years ago

This might relate to #124. We also have the Twitter-specific URI filter to handle Ajax-based navigation but that seems ad hoc.

machawk1 commented 8 years ago

This also occurs on Google Maps when entering an address/place, note that Mink does not re-query the aggregator.

machawk1 commented 8 years ago

Still verifiably an issue, replicable by clicking on a username on Twitter.

machawk1 commented 8 years ago

Mink functions to some extent on Twitter but navigation within Twitter.com is not consistently caught and processed.