Electron set cookie

后端 未结 3 1950
终归单人心
终归单人心 2021-01-25 14:11

I am new to electron and converting an web app to desktop application.I am loading pages from file system.Cookies are working if pages are served from web server but when I load

3条回答
  •  独厮守ぢ
    2021-01-25 14:42

    Well, I want to answer my question in case somebody is having the same problem. I have fixed the cookie problem by registerStandardSchemes. The sample code is as follows and code works for saving cookies from web pages as well:

    protocol.registerStandardSchemes(["app"], {
        secure: true
    });
    

    and on ready event

    protocol.registerFileProtocol('app', (request, callback) => {
        const urls = request.url.substr(6)
        const parsedUrl = url.parse(urls);
        // extract URL path
        const pathname = `.${parsedUrl.pathname}`;
        // based on the URL path, extract the file extention. e.g. .js, .doc, ...
        const ext = path.parse(pathname).ext;
        callback({
           path: path.normalize(`${__dirname}/${parsedUrl.pathname}`)
        })
    }, (error) => {
        if (error) {
            console.error('Failed to register protocol');
        }
    });
    

提交回复
热议问题