Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displays a white screen Loading and reports an error [Cannot read properties of undefined (reading 'getHighEntropyValues')] #116

Open
hanshou101 opened this issue Oct 27, 2023 · 73 comments
Labels
bug Something isn't working right

Comments

@hanshou101
Copy link

Scene

When I open NotionRepackged, it displays a white screen Loading and reports an error [Cannot read properties of undefined (reading 'getHighEntropyValues')] on the command line.

@hanshou101 hanshou101 added the bug Something isn't working right label Oct 27, 2023
@hanshou101
Copy link
Author

hanshou101 commented Oct 27, 2023

Fix Solution

#112

I solved it, it's essentially the same problem as Can't type colon ":" and forward slash "/" · Issue #112 · notion-enhancer/notion-repackaged.

Thank you @[@dario-99] for this brother’s contribution.

root cause:

After Notion is updated to the latest version, it references the API of [navigator.userAgentData.getHighEntropyValues]. And this [navigator.userAgentData] does not exist in the current Electron version of Notion-Repackeged.
Therefore, it is equivalent to getting [getHighEntropyValues] from [undefined].

solution:

I looked for the polyfill of [navigator.userAgentData.getHighEntropyValues] and found this article:

User Agent Client Hints API (navigator.userAgentData) polyfill and ponyfill

Especially in the [user-agent-data.js] file

It should be noted that I modified the following places according to my own needs:

  1. Manually executed [polyfill()] and [ponyfill()].
  2. In [location.protocol] of [polyfill method], I relaxed the restrictions, allowing both https and http protocols. (This modification I made may be redundant. But it doesn’t matter)

Below is my code file:

pay attention!!!
pay attention!!!
pay attention!!!

  1. Please refer to brother [@Z-nkk]’s suggestion Maybe Typo Sugesstion.
    1.1. I copied these js codes from links on the Internet. They work fine on my machine. But I didn't test other environments.
    1.2. If there is a problem with startup, there may be environmental differences (or other related js typo error code), please refer to the above link, namely [ line 57: platformVersion = padVersion(m2[2].replace(/_/g, '.')) ; , fix it to: platformVersion = padVersion(m[2].replace(/_/g, '.')); ]
(function __polyfill_2() {
    function getClientHints(navigator) {
        let { userAgent } = navigator;
        let mobile, platform = '', platformVersion = '', architecture = '', bitness = '', model = '', uaFullVersion = '', fullVersionList = [];
        let platformInfo = userAgent;
        let found = false;
        let versionInfo = userAgent.replace(/\(([^)]+)\)?/g, ($0, $1) => {
            if (!found) {
                platformInfo = $1;
                found = true;
            }
            return '';
        });
        let items = versionInfo.match(/(\S+)\/(\S+)/g);
        let webview = false;
        // detect mobile
        mobile = userAgent.indexOf('Mobile') !== -1;
        let m;
        let m2;
        // detect platform
        if ((m = /Windows NT (\d+(\.\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'Windows';
            // see https://docs.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
            let nt2win = {
                '6.1': '0.1', // win-7
                '6.2': '0.2', // win-8
                '6.3': '0.3', // win-8.1
                '10.0': '10.0', // win-10
                '11.0': '13.0', // win-11
            };
            let ver = nt2win[m[1]];
            if (ver)
                platformVersion = padVersion(ver, 3);
            if ((m2 = /\b(WOW64|Win64|x64)\b/.exec(platformInfo)) !== null) {
                architecture = 'x86';
                bitness = '64';
            }
        } else if ((m = /Android (\d+(\.\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'Android';
            platformVersion = padVersion(m[1]);
            if ((m2 = /Linux (\w+)/.exec(navigator.platform)) !== null) {
                if (m2[1]) {
                    m2 = parseArch(m2[1]);
                    architecture = m2[0];
                    bitness = m2[1];
                }
            }
        } else if ((m = /(iPhone|iPod touch); CPU iPhone OS (\d+(_\d+)*)/.exec(platformInfo)) !== null) {
            // see special notes at https://www.whatismybrowser.com/guides/the-latest-user-agent/safari
            platform = 'iOS';
            platformVersion = padVersion(m[2].replace(/_/g, '.'));
        } else if ((m = /(iPad); CPU OS (\d+(_\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'iOS';
            platformVersion = padVersion(m[2].replace(/_/g, '.'));
        } else if ((m = /Macintosh; (Intel|\w+) Mac OS X (\d+(_\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'macOS';
            platformVersion = padVersion(m2[2].replace(/_/g, '.'));
        } else if ((m = /Linux/.exec(platformInfo)) !== null) {
            platform = 'Linux';
            platformVersion = '';
            // TODO
        } else if ((m = /CrOS (\w+) (\d+(\.\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'Chrome OS';
            platformVersion = padVersion(m[2]);
            m2 = parseArch(m[1]);
            architecture = m2[0];
            bitness = m2[1];
        }
        if (!platform) {
            platform = 'Unknown';
        }
        // detect fullVersionList / brands
        let notABrand = { brand: ' Not;A Brand', version: '99.0.0.0' };
        if ((m = /Chrome\/(\d+(\.\d+)*)/.exec(versionInfo)) !== null && navigator.vendor === 'Google Inc.') {
            fullVersionList.push({ brand: 'Chromium', version: padVersion(m[1], 4) });
            if ((m2 = /(Edge?)\/(\d+(\.\d+)*)/.exec(versionInfo)) !== null) {
                let identBrandMap = {
                    'Edge': 'Microsoft Edge',
                    'Edg': 'Microsoft Edge',
                };
                let brand = identBrandMap[m[1]];
                fullVersionList.push({ brand: brand, version: padVersion(m2[2], 4) });
            } else {
                fullVersionList.push({ brand: 'Google Chrome', version: padVersion(m[1], 4) });
            }
            if (/\bwv\b/.exec(platformInfo)) {
                webview = true;
            }
        } else if ((m = /AppleWebKit\/(\d+(\.\d+)*)/.exec(versionInfo)) !== null && navigator.vendor === 'Apple Computer, Inc.') {
            fullVersionList.push({ brand: 'WebKit', version: padVersion(m[1]) });
            if (platform === 'iOS' && (m2 = /(CriOS|EdgiOS|FxiOS|Version)\/(\d+(\.\d+)*)/.exec(versionInfo)) != null) {
                let identBrandMap = { // no
                    'CriOS': 'Google Chrome',
                    'EdgiOS': 'Microsoft Edge',
                    'FxiOS': 'Mozilla Firefox',
                    'Version': 'Apple Safari',
                };
                let brand = identBrandMap[m2[1]];
                fullVersionList.push({ brand, version: padVersion(m2[2]) });
                if (items.findIndex((s) => s.startsWith('Safari/')) === -1) {
                    webview = true;
                }
            }
        } else if ((m = /Firefox\/(\d+(\.\d+)*)/.exec(versionInfo)) !== null) {
            fullVersionList.push({ brand: 'Firefox', version: padVersion(m[1]) });
        } else if ((m = /(MSIE |rv:)(\d+\.\d+)/.exec(platformInfo)) !== null) {
            fullVersionList.push({ brand: 'Internet Explorer', version: padVersion(m[2]) });
        } else {
            fullVersionList.push(notABrand);
        }
        uaFullVersion = fullVersionList.length > 0 ? fullVersionList[fullVersionList.length - 1] : '';
        let brands = fullVersionList.map((b) => {
            let pos = b.version.indexOf('.');
            let version = pos === -1 ? b.version : b.version.slice(0, pos);
            return { brand: b.brand, version };
        });
        // TODO detect architecture, bitness and model
        return {
            mobile,
            platform,
            brands,
            platformVersion,
            architecture,
            bitness,
            model,
            uaFullVersion,
            fullVersionList,
            webview
        };
    }

    function parseArch(arch) {
        switch (arch) {
            case 'x86_64':
            case 'x64':
                return ['x86', '64'];
            case 'x86_32':
            case 'x86':
                return ['x86', ''];
            case 'armv6l':
            case 'armv7l':
            case 'armv8l':
                return [arch, ''];
            case 'aarch64':
                return ['arm', '64'];
            default:
                return ['', ''];
        }
    }
    function padVersion(ver, minSegs = 3) {
        let parts = ver.split('.');
        let len = parts.length;
        if (len < minSegs) {
            for (let i = 0, lenToPad = minSegs - len; i < lenToPad; i += 1) {
                parts.push('0');
            }
            return parts.join('.');
        }
        return ver;
    }

    class NavigatorUAData {
        constructor() {
            this._ch = getClientHints(navigator);
            Object.defineProperties(this, {
                _ch: { enumerable: false },
            });
        }
        get mobile() {
            return this._ch.mobile;
        }
        get platform() {
            return this._ch.platform;
        }
        get brands() {
            return this._ch.brands;
        }
        getHighEntropyValues(hints) {
            return new Promise((resolve, reject) => {
                if (!Array.isArray(hints)) {
                    throw new TypeError('argument hints is not an array');
                }
                let hintSet = new Set(hints);
                let data = this._ch;
                let obj = {
                    mobile: data.mobile,
                    platform: data.platform,
                    brands: data.brands,
                };
                if (hintSet.has('architecture'))
                    obj.architecture = data.architecture;
                if (hintSet.has('bitness'))
                    obj.bitness = data.bitness;
                if (hintSet.has('model'))
                    obj.model = data.model;
                if (hintSet.has('platformVersion'))
                    obj.platformVersion = data.platformVersion;
                if (hintSet.has('uaFullVersion'))
                    obj.uaFullVersion = data.uaFullVersion;
                if (hintSet.has('fullVersionList'))
                    obj.fullVersionList = data.fullVersionList;
                resolve(obj);
            });
        }
        toJSON() {
            let data = this._ch;
            return {
                mobile: data.mobile,
                brands: data.brands,
            };
        }
    }
    Object.defineProperty(NavigatorUAData.prototype, Symbol.toStringTag, {
        enumerable: false,
        configurable: true,
        writable: false,
        value: 'NavigatorUAData'
    });

    function ponyfill() {
        return new NavigatorUAData(navigator);
    }
    function polyfill() {
        console.log("Try polyfill .  .  .");

        // When Notion , no need https?
        const ____use_https = false;

        if (
            (!____use_https || location.protocol === 'https:')
            && !navigator.userAgentData
        ) {
            console.log("Here,begin userAgentData polyfill .  .  .")
            let userAgentData = new NavigatorUAData(navigator);
            Object.defineProperty(Navigator.prototype, 'userAgentData', {
                enumerable: true,
                configurable: true,
                get: function getUseAgentData() {
                    return userAgentData;
                }
            });
            Object.defineProperty(window, 'NavigatorUAData', {
                enumerable: false,
                configurable: true,
                writable: true,
                value: NavigatorUAData
            });
            return true;
        }
        return false;
    }


    // Simple Apply this code.
    ponyfill();
    polyfill();
})();

@deanrobin333
Copy link

Can someone kindly explain in detail what we are to do. What am I to do with that code?

@hanshou101
Copy link
Author

hanshou101 commented Oct 27, 2023

@deanrobin333

The Simple One

A simple but temporary solution, [Ctrl+Shift+I] opens Electron’s Console, and then executes it.
Reference: temporary

The Complex One

A complex but permanent solution, unpack the Electron package, modify the preload.js file, and then reassemble the package.
Reference: permanent

@SuCicada
Copy link

SuCicada commented Oct 27, 2023

@deanrobin333

The Simple One

A simple but temporary solution, [Ctrl+Shift+I] opens Electron’s Console, and then executes it. Reference: temporary

The Complex One

A complex but permanent solution, unpack the Electron package, modify the preload.js file, and then reassemble the package. Reference: permanent

I try them all. like asar or paste code at the browser console.
But anyone can not work.
help
I just need to know where to put these code files in app.asar.

@FilipeAlmeida20
Copy link

Just followed the complex solution steps and managed to get it working. Thanks for the tips @hanshou101! 🎉

@Z-nkk
Copy link

Z-nkk commented Oct 27, 2023

@deanrobin333

The Simple One

A simple but temporary solution, [Ctrl+Shift+I] opens Electron’s Console, and then executes it. Reference: temporary

The Complex One

A complex but permanent solution, unpack the Electron package, modify the preload.js file, and then reassemble the package. Reference: permanent

I try them all. like asar or paste code at the browser console. But anyone can not work. help I just need to know where to put these code files in app.asar.

@SuCicada

Follow "The Complex One" and put the code in the app/render/preload.js file, and then repack.

Notice: there may be a typo in the code , line 57:platformVersion = padVersion(m2[2].replace(/_/g, '.')); , fix it to: platformVersion = padVersion(m[2].replace(/_/g, '.'));

Then it may work

@hersheysmcflurry
Copy link

thanks @Z-nkk! i couldn't get it to work due to the typo in this exact line. now it's working again.

also thanks @hanshou101 for providing the solution!

@SuCicada
Copy link

Oh, it works! That's awesome. Thank you.

In the past, my problem was that I left the app directory in /Applications/Notion Enhanced.app/Contents/Resources where I extracted app.asar.
So after removing it, Notion Enhanced started working again.

@vargn
Copy link

vargn commented Oct 27, 2023

This solution does not work for me on Manjaro. I followed the same steps as for the "can't type :" issue some month ago. Still i'm only seeing a blank screen with a loading circle in the middle.

        } else if ((m = /Linux/.exec(platformInfo)) !== null) {
            platform = 'Linux';
            platformVersion = '';

platformVersion is empty for Linux, could this be the reason for why it is not working for me on Manjaro?

@vargn
Copy link

vargn commented Oct 27, 2023

This solution does not work for me on Manjaro. I followed the same steps as for the "can't type :" issue some month ago. Still i'm only seeing a blank screen with a loading circle in the middle.

        } else if ((m = /Linux/.exec(platformInfo)) !== null) {
            platform = 'Linux';
            platformVersion = '';

platformVersion is empty for Linux, could this be the reason for why it is not working for me on Manjaro?

Adding a ; at the end of the last line before pasting the fix solved my issue. Thank you @dragonwocky

@acerspyro
Copy link

acerspyro commented Oct 27, 2023

If you're on Linux, I've wrapped it nicely into a Script.

Review the script's contents, mark as +x and run as root. This should patch your Notion Enhanced.

Tested to work on Fedora 39 with NE installed via RPM.

patch-notion-enhanced.sh

@sh8
Copy link

sh8 commented Oct 27, 2023

This script worked in Arch Linux! Saved my day! Thank you so much!

@teafoot
Copy link

teafoot commented Oct 27, 2023

@acerspyro thanks, the script worked on ubuntu as well

@hanshou101
Copy link
Author

@deanrobin333

The Simple One

A simple but temporary solution, [Ctrl+Shift+I] opens Electron’s Console, and then executes it. Reference: temporary

The Complex One

A complex but permanent solution, unpack the Electron package, modify the preload.js file, and then reassemble the package. Reference: permanent

I try them all. like asar or paste code at the browser console. But anyone can not work. help I just need to know where to put these code files in app.asar.

@SuCicada

Follow "The Complex One" and put the code in the app/render/preload.js file, and then repack.

Notice: there may be a typo in the code , line 57:platformVersion = padVersion(m2[2].replace(/_/g, '.')); , fix it to: platformVersion = padVersion(m[2].replace(/_/g, '.'));

Then it may work

Thank you brother, I have not fully audited this js code, it is mainly based on my search results on google.

It works in my environment, but I haven't tested it in other environments; thank you for your suggestions and fixes! ! !

I have incorporated your modification suggestions into the previous (to some extent not perfect) Solution .

Thanks for your addition! It will definitely help a lot of people.

@henfiber
Copy link

henfiber commented Oct 28, 2023

If you're on Linux, I've wrapped it nicely into a Script.

Review the script's contents, rename the extension to just .sh, mark as +x and run as root. This should patch your Notion Enhanced.

Tested to work on Fedora 39 with NE installed via RPM.

patch-notion-enhanced.sh

Thanks for the script, thanks to the OP for the fix and everyone for the corrections.

For me asar was not available in the package manager, so I installed globally with sudo npm install -g --engine-strict @electron/asar.

I also had to change the hardcoded path from /opt/Notion\ Enhanced/resources/ to /opt/Notion/resources (lines 41 and 331).

EDIT: I also had to perform the following changes to the script:

  • change EOL in line:62 to 'EOL' (see https://stackoverflow.com/a/22698106/1305020) because otherwise the ($0, $1) expression in line 69 were replaced with the name of the script and the first argument (unquoted) causing exceptions in preload.js and breaking other features in Notion.
  • add an empty new line before (function __polyfill_2() {
    (otherwise the first line was appended to an existing line in the preload.js script which was a comment, therefore breakin the script).

Here is a gist with my modifications.

@LoryPack
Copy link

The script also worked for me on Ubuntu, by installing asar with snap and changing /opt/Notion\ Enhanced/resources/ to /opt/Notion/resources (lines 41 and 331). Thanks

@shachar-ash
Copy link

Was anyone able to fix this issue on macOS?

@hersheysmcflurry
Copy link

hey @shachar-ash, i got it to work on macOS. however, do note the issue i listed in #117 after patching… i suggest you enable "tray menu" now in the NE menu if you haven't, then start patching.

@Mirissa-Youth
Copy link

@henfiber@Z-nkk THANK FOR YOU GUYS , the app acutualy work with your method!!!

@againo
Copy link

againo commented Nov 2, 2023

按照老哥的建议遵循操作把问题解决了!
1、找到/opt/Notion Enhanced文件夹
2、使用snap安装asar命令,系统提示我使用 --classic 选项安装成功
3、编辑/opt/Notion Enhanced/resources/app/renderer/preload.js 文件,把 author 老哥的代码贴到里面,注意要贴到这句代码的前面 //notion-enhancer
require('notion-enhancer')('renderer/preload', exports, (js) => eval(js))
4、根据zhhk老哥的建议修改 53行 把m2[2] -> m[2]
5、然后使用asar重新打包app文件夹,成功解决问题!

PS:
1、如果还不能解决问题,可以使用ctrl+shift+i快捷键打开后台查看问题
2、目前我测试下来整个编辑功能比较完整,但是ehanced的title仍然没有出现
3、把文件路径Notion Ehanced -> Notion 后无法打开文件
我是ubuntu 22.04TLS,使用xorg的gui

Thanks @hanshou101 @Z-nkk once more!

@alexblackkkkk
Copy link

alexblackkkkk commented Nov 3, 2023

Problem was solved on win11 using this method.

Here are instructions to help Chinese users who cannot read English well to solve this problem.
以下是帮英文不好的中文用户来解决该问题的说明…(参考楼上老哥的方法,写得略详细一点)

我是win11用户,折腾了半个小时,使用该方法已解决问题,帮和我一样的英文很菜的电脑小白解释一下:

【思路】
1.我们的目的是要修改一个preload.js的文件,所以首先要找到这个文件;
2.然后你发现这个文件在.asar格式的压缩包里,得解压后修改,再压缩回去;
3.为了解压.asar格式,你得安装解压它的工具。

【操作方法】
1.首先我们要找到preload.js。
打开notion-enhanced客户端,按Ctrl+Shift+I 打开开发者工具,选Sources选项卡,在左侧(no domain)里面睁大眼睛找到preload.js这个文件的地址,我的是在C:\Program Files\Notion Enhanced\resources\app.asar\renderer\preload.js

2.其次要安装解压.asar格式文件的工具。
我不知道sudo是啥,所以我安装了node和npm,然后再安装解压asar用的模块。先说安装node,参考了这篇文章:https://timberkito.com/?p=145
难点在于添加环境变量,必须添加环境变量后,你输入查版本命令才能返回正常结果。

然后安装asar,我参考这篇文章:https://www.cnblogs.com/cutewrp/p/14723913.html
这个直接安装后,我输入asar -V还是报错,我又把asar手动加进环境变量,才正常了。

3.最后解压asar,修改preload.js文件。
解压和重新压缩的方法还是参考:https://www.cnblogs.com/cutewrp/p/14723913.html

备份之后解压,然后修改preload文件,就是把贴主提供的代码粘贴到最后两行的前面,也就是下面这段代码的前面
//notion-enhancer
require('notion-enhancer')('renderer/preload', exports, (js) => eval(js))

然后贴主提供的代码的57行有个错误,你要手动把这一行的m2[2]改成m[2]

修改后重新打包,替换掉原路径里的app.asar文件,就大功告成了。

不过……修复之后你会发现你之前在notion-enhanced里的设置都丢失了,如果有备份的话直接上传就行,如果没备份……那只能手动重新设置了。建议以后还是勤快备份为好。

——————————

感谢楼上所有人提供的参考信息。祝大家都能顺利修改~

Thanks to everyone above for the reference information. Good luck to all!

@campbelldrobert
Copy link

I'm thankful for this post for making the app work on my ubuntu install, however I do notice the multiple account feature no longer works (which before this error worked fine I believe).

Now it's only 1 account that it allows me to use, when trying to add the second account.

@henfiber
Copy link

henfiber commented Nov 3, 2023

@GRACEBL

THANK FOR YOU GUYS , the app acutualy work with your method!!!

I updated my comment with a few extra edits I needed to make and a link to a new gist.

Without these fixes, I could not open external links and the "find in page" function did not work.

@fengmao31
Copy link

If you're on Linux, I've wrapped it nicely into a Script.

Review the script's contents, mark as +x and run as root. This should patch your Notion Enhanced.

Tested to work on Fedora 39 with NE installed via RPM.

patch-notion-enhanced.sh

Can you make a windows version if you have free time? I think many people need it.

@GGotha
Copy link

GGotha commented Feb 27, 2024

If you're on Linux, I've wrapped it nicely into a Script.

Review the script's contents, mark as +x and run as root. This should patch your Notion Enhanced.

Tested to work on Fedora 39 with NE installed via RPM.

patch-notion-enhanced.sh

It worked here on Ubuntu 22.04

@vfairon
Copy link

vfairon commented Feb 28, 2024 via email

@dragonwocky
Copy link
Member

A script for windows was posted in the Discord here, if you'd like to give it a try @fengmao31.

@fengmao31
Copy link

A script for windows was posted in the Discord here, if you'd like to give it a try @fengmao31.

something wrong with the Discord link.

@dragonwocky
Copy link
Member

@fengmao31 you will need to join the server first, before you are able to jump to specific messages from a link

@acerspyro
Copy link

A script for windows was posted in the Discord here, if you'd like to give it a try @fengmao31.

I actually posted it as part of my original GitLab snippet (last file): https://gitlab.com/-/snippets/3615945

@shun1249844726
Copy link

解决方案有点乱,所以这里将解决方案合并到一条评论中:

  1. 安装asar
sudo pacman -S asar

或者

npm i -g asar
  1. /opt/Notion/resources/app.asar
  2. 提取内容
sudo asar extract app.asar app
  1. 将以下代码粘贴到 的末尾./app/renderer/preload.js
(function __polyfill_2() {
    function getClientHints(navigator) {
        let { userAgent } = navigator;
        let mobile, platform = '', platformVersion = '', architecture = '', bitness = '', model = '', uaFullVersion = '', fullVersionList = [];
        let platformInfo = userAgent;
        let found = false;
        let versionInfo = userAgent.replace(/\(([^)]+)\)?/g, ($0, $1) => {
            if (!found) {
                platformInfo = $1;
                found = true;
            }
            return '';
        });
        let items = versionInfo.match(/(\S+)\/(\S+)/g);
        let webview = false;
        // detect mobile
        mobile = userAgent.indexOf('Mobile') !== -1;
        let m;
        let m2;
        // detect platform
        if ((m = /Windows NT (\d+(\.\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'Windows';
            // see https://docs.microsoft.com/en-us/microsoft-edge/web-platform/how-to-detect-win11
            let nt2win = {
                '6.1': '0.1', // win-7
                '6.2': '0.2', // win-8
                '6.3': '0.3', // win-8.1
                '10.0': '10.0', // win-10
                '11.0': '13.0', // win-11
            };
            let ver = nt2win[m[1]];
            if (ver)
                platformVersion = padVersion(ver, 3);
            if ((m2 = /\b(WOW64|Win64|x64)\b/.exec(platformInfo)) !== null) {
                architecture = 'x86';
                bitness = '64';
            }
        } else if ((m = /Android (\d+(\.\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'Android';
            platformVersion = padVersion(m[1]);
            if ((m2 = /Linux (\w+)/.exec(navigator.platform)) !== null) {
                if (m2[1]) {
                    m2 = parseArch(m2[1]);
                    architecture = m2[0];
                    bitness = m2[1];
                }
            }
        } else if ((m = /(iPhone|iPod touch); CPU iPhone OS (\d+(_\d+)*)/.exec(platformInfo)) !== null) {
            // see special notes at https://www.whatismybrowser.com/guides/the-latest-user-agent/safari
            platform = 'iOS';
            platformVersion = padVersion(m[2].replace(/_/g, '.'));
        } else if ((m = /(iPad); CPU OS (\d+(_\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'iOS';
            platformVersion = padVersion(m[2].replace(/_/g, '.'));
        } else if ((m = /Macintosh; (Intel|\w+) Mac OS X (\d+(_\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'macOS';
            platformVersion = padVersion(m[2].replace(/_/g, '.'));
        } else if ((m = /Linux/.exec(platformInfo)) !== null) {
            platform = 'Linux';
            platformVersion = '';
            // TODO
        } else if ((m = /CrOS (\w+) (\d+(\.\d+)*)/.exec(platformInfo)) !== null) {
            platform = 'Chrome OS';
            platformVersion = padVersion(m[2]);
            m2 = parseArch(m[1]);
            architecture = m2[0];
            bitness = m2[1];
        }
        if (!platform) {
            platform = 'Unknown';
        }
        // detect fullVersionList / brands
        let notABrand = { brand: ' Not;A Brand', version: '99.0.0.0' };
        if ((m = /Chrome\/(\d+(\.\d+)*)/.exec(versionInfo)) !== null && navigator.vendor === 'Google Inc.') {
            fullVersionList.push({ brand: 'Chromium', version: padVersion(m[1], 4) });
            if ((m2 = /(Edge?)\/(\d+(\.\d+)*)/.exec(versionInfo)) !== null) {
                let identBrandMap = {
                    'Edge': 'Microsoft Edge',
                    'Edg': 'Microsoft Edge',
                };
                let brand = identBrandMap[m[1]];
                fullVersionList.push({ brand: brand, version: padVersion(m2[2], 4) });
            } else {
                fullVersionList.push({ brand: 'Google Chrome', version: padVersion(m[1], 4) });
            }
            if (/\bwv\b/.exec(platformInfo)) {
                webview = true;
            }
        } else if ((m = /AppleWebKit\/(\d+(\.\d+)*)/.exec(versionInfo)) !== null && navigator.vendor === 'Apple Computer, Inc.') {
            fullVersionList.push({ brand: 'WebKit', version: padVersion(m[1]) });
            if (platform === 'iOS' && (m2 = /(CriOS|EdgiOS|FxiOS|Version)\/(\d+(\.\d+)*)/.exec(versionInfo)) != null) {
                let identBrandMap = { // no
                    'CriOS': 'Google Chrome',
                    'EdgiOS': 'Microsoft Edge',
                    'FxiOS': 'Mozilla Firefox',
                    'Version': 'Apple Safari',
                };
                let brand = identBrandMap[m2[1]];
                fullVersionList.push({ brand, version: padVersion(m2[2]) });
                if (items.findIndex((s) => s.startsWith('Safari/')) === -1) {
                    webview = true;
                }
            }
        } else if ((m = /Firefox\/(\d+(\.\d+)*)/.exec(versionInfo)) !== null) {
            fullVersionList.push({ brand: 'Firefox', version: padVersion(m[1]) });
        } else if ((m = /(MSIE |rv:)(\d+\.\d+)/.exec(platformInfo)) !== null) {
            fullVersionList.push({ brand: 'Internet Explorer', version: padVersion(m[2]) });
        } else {
            fullVersionList.push(notABrand);
        }
        uaFullVersion = fullVersionList.length > 0 ? fullVersionList[fullVersionList.length - 1] : '';
        let brands = fullVersionList.map((b) => {
            let pos = b.version.indexOf('.');
            let version = pos === -1 ? b.version : b.version.slice(0, pos);
            return { brand: b.brand, version };
        });
        // TODO detect architecture, bitness and model
        return {
            mobile,
            platform,
            brands,
            platformVersion,
            architecture,
            bitness,
            model,
            uaFullVersion,
            fullVersionList,
            webview
        };
    }

    function parseArch(arch) {
        switch (arch) {
            case 'x86_64':
            case 'x64':
                return ['x86', '64'];
            case 'x86_32':
            case 'x86':
                return ['x86', ''];
            case 'armv6l':
            case 'armv7l':
            case 'armv8l':
                return [arch, ''];
            case 'aarch64':
                return ['arm', '64'];
            default:
                return ['', ''];
        }
    }
    function padVersion(ver, minSegs = 3) {
        let parts = ver.split('.');
        let len = parts.length;
        if (len < minSegs) {
            for (let i = 0, lenToPad = minSegs - len; i < lenToPad; i += 1) {
                parts.push('0');
            }
            return parts.join('.');
        }
        return ver;
    }

    class NavigatorUAData {
        constructor() {
            this._ch = getClientHints(navigator);
            Object.defineProperties(this, {
                _ch: { enumerable: false },
            });
        }
        get mobile() {
            return this._ch.mobile;
        }
        get platform() {
            return this._ch.platform;
        }
        get brands() {
            return this._ch.brands;
        }
        getHighEntropyValues(hints) {
            return new Promise((resolve, reject) => {
                if (!Array.isArray(hints)) {
                    throw new TypeError('argument hints is not an array');
                }
                let hintSet = new Set(hints);
                let data = this._ch;
                let obj = {
                    mobile: data.mobile,
                    platform: data.platform,
                    brands: data.brands,
                };
                if (hintSet.has('architecture'))
                    obj.architecture = data.architecture;
                if (hintSet.has('bitness'))
                    obj.bitness = data.bitness;
                if (hintSet.has('model'))
                    obj.model = data.model;
                if (hintSet.has('platformVersion'))
                    obj.platformVersion = data.platformVersion;
                if (hintSet.has('uaFullVersion'))
                    obj.uaFullVersion = data.uaFullVersion;
                if (hintSet.has('fullVersionList'))
                    obj.fullVersionList = data.fullVersionList;
                resolve(obj);
            });
        }
        toJSON() {
            let data = this._ch;
            return {
                mobile: data.mobile,
                brands: data.brands,
            };
        }
    }
    Object.defineProperty(NavigatorUAData.prototype, Symbol.toStringTag, {
        enumerable: false,
        configurable: true,
        writable: false,
        value: 'NavigatorUAData'
    });

    function ponyfill() {
        return new NavigatorUAData(navigator);
    }
    function polyfill() {
        console.log("Try polyfill .  .  .");

        // When Notion , no need https?
        const ____use_https = false;

        if (
            (!____use_https || location.protocol === 'https:')
            && !navigator.userAgentData
        ) {
            console.log("Here,begin userAgentData polyfill .  .  .")
            let userAgentData = new NavigatorUAData(navigator);
            Object.defineProperty(Navigator.prototype, 'userAgentData', {
                enumerable: true,
                configurable: true,
                get: function getUseAgentData() {
                    return userAgentData;
                }
            });
            Object.defineProperty(window, 'NavigatorUAData', {
                enumerable: false,
                configurable: true,
                writable: true,
                value: NavigatorUAData
            });
            return true;
        }
        return false;
    }


    // Simple Apply this code.
    ponyfill();
    polyfill();
})();
  1. 重新包装
sudo asar pack app app.asar

谢谢@dario-99,@Z-nkk@hanshou101❤️

来源

汉手101 Dario-99 Z-nkk

require('notion-enhancer')('renderer/preload', exports, (js) => eval(js))
last line need add ";"
require('notion-enhancer')('renderer/preload', exports, (js) => eval(js));

@tomasApo
Copy link

tomasApo commented Mar 9, 2024

Solution for ubunto/POP OS.

Have notion-enhancer installed
Using the script mentioned above.

  1. git clone https://gitlab.com/-/snippets/3615945
  2. cd 3615945/
  3. chmod +x
  4. sudo ./patch-notion-enhanced.linux.sh

Done, run notion-enhancer now and it should work!

Thank you @MaximTh

@colinschwegmann
Copy link

For anyone here on Ubuntu 23.10 or further with the error

E: Unable to locate package asar

asar isn't available in the usual apt packages. I think you could add it as a package repository in Ubuntu 23.10 but I couldn't be bothered to figure it out.

Ubuntu recommends an alternative as

snap install asar --classic 

which worked just fine with the rest of the above script and my notion-app-enhanced is working just fine now.

@dragonwocky
Copy link
Member

dragonwocky commented Mar 26, 2024

@colinschwegmann asar is distributed as an npm module, so the recommended way to call it is to via: npx @electron/asar extract ... (assuming Node,js is installed, this does not require asar itself to be specifically installed).

@colinschwegmann
Copy link

@dragonwocky no use telling me that. The script tries to install it via apt. That won't work on stock Ubuntu so I've provided a solution. You or someone else is welcome to change that script to adhere to your recommendations - I'm simply stating what I needed to do get it to work.

@ThomasBerneHCSE
Copy link

ThomasBerneHCSE commented Apr 15, 2024

for arch based distros, install this package instead: https://aur.archlinux.org/packages/notion-app-electron

@MahmoudKhalefa2020
Copy link

MahmoudKhalefa2020 commented Apr 26, 2024

I don't know what I can do ?

image

@Izurai
Copy link

Izurai commented May 27, 2024

Thank y'all

@Fros1er
Copy link

Fros1er commented Jul 15, 2024

If you're on Linux, I've wrapped it nicely into a Script.
Review the script's contents, rename the extension to just .sh, mark as +x and run as root. This should patch your Notion Enhanced.
Tested to work on Fedora 39 with NE installed via RPM.
patch-notion-enhanced.sh.txt DO NOT USE THAT!!!

Thanks for the script, thanks to the OP for the fix and everyone for the corrections.

For me asar was not available in the package manager, so I installed globally with sudo npm install -g --engine-strict @electron/asar.

I also had to change the hardcoded path from /opt/Notion\ Enhanced/resources/ to /opt/Notion/resources (lines 41 and 331).

EDIT: I also had to perform the following changes to the script:

  • change EOL in line:62 to 'EOL' (see https://stackoverflow.com/a/22698106/1305020) because otherwise the ($0, $1) expression in line 69 were replaced with the name of the script and the first argument (unquoted) causing exceptions in preload.js and breaking other features in Notion.
  • add an empty new line before (function __polyfill_2() {
    (otherwise the first line was appended to an existing line in the preload.js script which was a comment, therefore breakin the script).

Here is a gist with my modifications.

Thanks! That saved my day.
A little sugesstion, could you update the link to newest version of script in your quote? I downloaded the older txt file in quote by mistake.
The older script complaint "It looks like your browser is currently blocking popups. Please allow pop-ups to continue". It's hard to realize where the bug is :(

@XaMiNeZH
Copy link

XaMiNeZH commented Oct 6, 2024

thank you so much!! it worked.

@01001010x
Copy link

If you're on Linux, I've wrapped it nicely into a Script.

Review the script's contents, mark as +x and run as root. This should patch your Notion Enhanced.

Tested to work on Fedora 39 with NE installed via RPM.

patch-notion-enhanced.sh

Worked for me in Ubuntu 22.04 modifying the paths in the script from:

cd /opt/Notion \Enhanced/resources/

to

cd /opt/Notion/resources/

Thank you!

@OptiTeck
Copy link

If you're on Linux, I've wrapped it nicely into a Script.

Review the script's contents, mark as +x and run as root. This should patch your Notion Enhanced.

Tested to work on Fedora 39 with NE installed via RPM.

patch-notion-enhanced.sh

Works on manjaro also, thank you so much!

@RichardYann
Copy link

If you're on Linux, I've wrapped it nicely into a Script.

Review the script's contents, mark as +x and run as root. This should patch your Notion Enhanced.

Tested to work on Fedora 39 with NE installed via RPM.

patch-notion-enhanced.sh

Wonderful! Worked on Ubuntu 20!Thank you so much!!!

@Rope-a-dope
Copy link

Rope-a-dope commented Nov 17, 2024

If you're on Linux, I've wrapped it nicely into a Script.

Review the script's contents, mark as +x and run as root. This should patch your Notion Enhanced.

Tested to work on Fedora 39 with NE installed via RPM.

patch-notion-enhanced.sh

Thanks! It worked on Fedora 41. But there is one correction.

Change line 41 to

 cd /opt/Notion/resources/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working right
Projects
None yet
Development

No branches or pull requests