Closed franzenzenhofer closed 7 years ago
PRIO feature medium
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.
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)
done?
yes should be done.
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
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)?
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.
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 }, '*');
});
});
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)
a fetch now delives some meta information about the response, the response body is now in available in response.body
@franzenzenhofer awesome 👏
@franzenzenhofer let me know if this works for you so we can close this issue or if we need to iterate over it again.
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 .
k will close this issue. added as enhancement issue.
this.fetch
ignores cross origin headers