franzenzenhofer / f19n-obtrusive-livetest

A sandboxed, extendable testing chrome extension and framework! It runs pre-defined and custom tests on each page that you visit.
https://chrome.google.com/webstore/detail/f19n-obstrusive-live-test/jbnaibigcohjfefpfocphcjeliohhold?hl=en
55 stars 1 forks source link

background fetch accessible from rules #52

Closed franzenzenhofer closed 7 years ago

franzenzenhofer commented 7 years ago

this.fetch

ignores cross origin headers

franzenzenhofer commented 7 years ago

PRIO feature medium

neuling commented 7 years ago

i did a quick test about the backgroundPage fetch thing and realised that due to the security policies of chrome we cannot break out of the sandbox page where all the rules gets evaluated. so there is no access to any chrome.* functions.

the only way to communicate with the backgroundPage is via postMessage (like we do it to run rules). downside: it's not as simple as initially thought. probably 1-2 hours of work.

franzenzenhofer commented 7 years ago

would be a necessary feature as I already now spammed the core logic with stuff that should not be in there (soft404 check, robots.txt check)

franzenzenhofer commented 7 years ago

done?

neuling commented 7 years ago

yes should be done.

franzenzenhofer commented 7 years ago

just a questions

function(page, done) {
  this.fetch('https://orf.at', { responseFormat: 'text' }, (response) => {
    done(this.createResult('FETCH', `response from orf.at: ${response.length}`, 'info'));
  });
}

what is the syntax (is there a syntax) if fetch fails?

note: fetch works awesomly in src/public/default-rules/dom-detect-client-side-rendering.js

neuling commented 7 years ago

hm good question. what kind of errors would you like to catch? different http responses? or something like "net::ERR_NAME_NOT_RESOLVED" (website not reachable)?

neuling commented 7 years ago

in a perfect world i would pass the raw response from fetch as the first argument but since we communicate within iframes, i can only pass JSON around. so i need to catch all possible errors and uses cases on the chrome side of the extension and convert it to JSON.

neuling commented 7 years ago

here is the the interface where i run the actual fetch and return the response via postMessage to the sandbox:

fetch(url, options || {}).then((response) => {
  response[responseFormat || 'text']().then((data) => {
    event.source.postMessage({ command: 'fetchResult', response: data, runId }, '*');
  });
});
franzenzenhofer commented 7 years ago

in a simple world i would just be happy if i get to know within the rule if the fetch failed (not even necessary to know why if this is the hard)

anyway / not necessary for MVP (but a note in the documentation would be a good idea)

franzenzenhofer commented 7 years ago

image a fetch now delives some meta information about the response, the response body is now in available in response.body

neuling commented 7 years ago

@franzenzenhofer awesome 👏

neuling commented 7 years ago

@franzenzenhofer let me know if this works for you so we can close this issue or if we need to iterate over it again.

franzenzenhofer commented 7 years ago

everythink OK, works great, error handling with status information good enough (if fetch fails of other reasons not covered, but not critical)

On Tue, May 2, 2017 at 11:18 AM, Moritz Kobrna notifications@github.com wrote:

@franzenzenhofer https://github.com/franzenzenhofer let me know if this works for you so we can close this issue or if we need to iterate over it again.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/franzenzenhofer/f19n-livetest-chrome-extension/issues/52#issuecomment-298571999, or mute the thread https://github.com/notifications/unsubscribe-auth/AATudov7z8FN1UzouZ52aimHKgqNuhcFks5r1vTkgaJpZM4MZQ5N .

neuling commented 7 years ago

k will close this issue. added as enhancement issue.