Fix cookie detection in WebExtension driver

main
Elbert Alias 4 years ago
parent 360da3853e
commit ed8a32f177

@ -171,6 +171,14 @@ const Content = {
: resolve() : resolve()
)) ))
const cookies = document.cookie.split('; ').reduce(
(cookies, cookie) => ({
...cookies,
[cookie.split('=').shift()]: [cookie.split('=').pop()],
}),
{}
)
// CSS rules // CSS rules
let css = [] let css = []
@ -235,7 +243,7 @@ const Content = {
} }
} }
Content.cache = { html, css, scripts, meta } Content.cache = { html, css, scripts, meta, cookies }
await Content.driver('onContentLoad', [ await Content.driver('onContentLoad', [
url, url,

@ -423,18 +423,15 @@ const Driver = {
*/ */
async onContentLoad(url, items, language, requires) { async onContentLoad(url, items, language, requires) {
try { try {
const { hostname } = new URL(url) items.cookies = items.cookies || {}
items.cookies = ( //
;(
await promisify(chrome.cookies, 'getAll', { await promisify(chrome.cookies, 'getAll', {
domain: `.${hostname}`, url,
}) })
).reduce( ).forEach(
(cookies, { name, value }) => ({ ({ name, value }) => (items.cookies[name.toLowerCase()] = [value])
...cookies,
[name.toLowerCase()]: [value],
}),
{}
) )
await Driver.onDetect( await Driver.onDetect(