Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issues with re-writing hyperlinks #66

Open
serapath opened this issue Feb 16, 2021 · 1 comment
Open

issues with re-writing hyperlinks #66

serapath opened this issue Feb 16, 2021 · 1 comment

Comments

@serapath
Copy link

maybe it needs an additional option, but:

  1. using <iframe is="x-frame-bypass" src="https://api.allorigins.win/raw?url=${url}"></iframe>
  2. where url = "https://example.com/demo.html"
  3. and contains a relative hyperlink to e.g. /example/bar.html
  4. it is re-written to "https://api.allorigins.win/example/bar.html"
  5. but should probably be re-written to:
    • https://api.allorigins.win/raw?url=https://example.com/example/bar.html

Is that something that could be added?

@serapath
Copy link
Author

just checked the source code - it's in fact not re-written at all, but instead that's just how the relative link works :-)

maybe something that would be useful to allow more freedom is to add postMessage interface to the iframe, like:

window.callbacks = {}
var counter = 0
onmessage = ({ data: code }) => {
  const id = counter++
  parent.postMessage(JSON.stringify({ type: 'start', id, data: code })
  new Promise((resolve, reject) => {
    window.callbacks[id] = { resolve, reject }
  }).then(result => {
    parent.postMessage(JSON.stringify({ type: 'result', id, data: result })
  }).catch(error => {
    error.stack
    parent.postMessage(JSON.stringify({ type: 'error', id, data: error })
  })
  const source = `;(async (id, result) {
    try {
      const { resolve } = window.callbacks[id];
      ${code};
      resolve(result)
    } catch (error) {
      const { reject } = window.callbacks[id]
      reject(error)
    }
  })(${id})`
  eval(source)
}

So a user can then scrape the page and interact properly with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant