Skip to main content

FETCH_JS

Constant FETCH_JS 

Source
pub const FETCH_JS: &str = r#"
(async function(argsJson) {
    const args = JSON.parse(argsJson);
    const r = await fetch(args.url, {
        method: args.method || 'GET',
        headers: args.headers || {},
        body: args.body,
        credentials: 'include',
    });
    const text = await r.text();
    const headers = {};
    r.headers.forEach((v,k) => { headers[k] = v; });
    return JSON.stringify({ status: r.status, statusText: r.statusText, headers, body: text });
})
"#;
Expand description

Performs a fetch from the page context. Receives JSON-string args.