x-frame-bypass icon indicating copy to clipboard operation
x-frame-bypass copied to clipboard

Cannot navigate inside iframe

Open thdoan opened this issue 2 years ago • 2 comments

I have encountered a new issue after successfully loading https://www.hackernews.com/ inside an iframe:

image

This prevents navigation inside this iframe, which makes the site unusable. How do you guys work around this?

thdoan avatar Feb 15 '23 02:02 thdoan

My theory is that in order to make this work, I'll need to move this code outside of the inline block and inside its own JS file:

        this.srcdoc = data.replace(/<\/head>/i, `<base href="${url}">
  <script>
  // X-Frame-Bypass navigation event handlers
  function onChatInABoxClick(e) {
    if (frameElement && document.activeElement && document.activeElement.href) {
      e.preventDefault();
      frameElement.load(document.activeElement.href);
    }
  }
  function onChatInABoxSubmit(e) {
    if (frameElement && document.activeElement && document.activeElement.form && document.activeElement.form.action) {
      e.preventDefault();
      if (document.activeElement.form.method === 'post') {
        frameElement.load(document.activeElement.form.action, {
          method: 'post',
          body: new FormData(document.activeElement.form),
        });
      } else {
        frameElement.load(document.activeElement.form.action + '?' + new URLSearchParams(new FormData(document.activeElement.form)));
      }
    }
  }
  document.addEventListener('click', onChatInABoxClick);
  document.addEventListener('submit', onChatInABoxSubmit);
  </script>
  </head>`);

thdoan avatar Feb 15 '23 02:02 thdoan

Okay, moving the navigation event handlers into its own script resolved two of the errors, but these two errors remain:

image

Any ideas on how to resolve these remaining errors?

thdoan avatar Feb 15 '23 02:02 thdoan