Ember - Change current route from browser console

285 views Asked by At

I am not at all Ember developer, but I would like to change current route from browser console. Is it possible at all to access correctly Ember, e.g. Ember.Router.prototype.transitionTo('/feed')?

Version of the website is 3.16.9

1

There are 1 answers

0
crotoan On

After a lot of research, I have found out possible solutions that you can use. I was trying to achieve it on Linkedin website via Chrome Extension

function runEmbedded(path) {
  const namespaces = window.Ember.Namespace.NAMESPACES;
  let application;
  namespaces.forEach(function (namespace) {
    if (namespace instanceof window.Ember.Application) {
      application = namespace;
      return false;
    }
  });
  application.__container__.lookup('router:main').transitionTo(path);
}

const payload = '/some/new-path'
script.text = `(${runEmbedded.toString()})('${payload}');`;
document.documentElement.appendChild(script);

Second solution/hack:

Another possible hack to use, when the website is not listening to pushState/replaceState actions from History API is to push state 2 times and then go back. Please remember that's only a hack.

history.pushState({}, '', msg.payload);
history.pushState({}, '', msg.payload);
history.back();