notion-enhancer / notion-repackaged

notion executables with the notion-enhancer embedded & a vanilla port of the official app to linux
https://notion-enhancer.github.io/getting-started/installation
MIT License
905 stars 51 forks source link

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

Open hanshou101 opened 10 months ago

hanshou101 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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

hanshou101 commented 10 months ago

@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 commented 10 months ago

@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 commented 10 months ago

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

Z-nkk commented 10 months ago

@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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

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

teafoot commented 10 months ago

@acerspyro thanks, the script worked on ubuntu as well

hanshou101 commented 10 months ago

@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 commented 10 months ago

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:

Here is a gist with my modifications.

LoryPack commented 10 months ago

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 commented 10 months ago

Was anyone able to fix this issue on macOS?

hersheysmcflurry commented 10 months ago

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.

GRACEBL commented 10 months ago

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

againo commented 10 months ago

按照老哥的建议遵循操作把问题解决了! 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 commented 10 months ago

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 commented 10 months ago

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 commented 10 months ago

@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.

callmenoodles commented 9 months ago

The solution is a bit all over the place, so here's the solution combined into one comment:

  1. Install asar
    sudo pacman -S asar

    or

    npm i -g asar
  2. Go to /opt/Notion/resources/app.asar
  3. Extract the contents
    sudo asar extract app.asar app
  4. Paste the following code at the end of ./app/renderer/preload.js:

(function __polyfill2() { 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();

})();

6. Repack

sudo asar pack app app.asar



Thanks to @dario-99, @Z-nkk and @hanshou101 ❤️ 

### Sources
[Hanshou101](https://github.com/notion-enhancer/notion-repackaged/issues/116#issuecomment-1782243815)
[Dario-99](https://github.com/notion-enhancer/notion-repackaged/issues/112#issuecomment-1655456101)
[Z-nkk](https://github.com/notion-enhancer/notion-repackaged/issues/116#issuecomment-1782556490)
aspedrini commented 9 months ago

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

Big thanks! Worked on Kubuntu.

levin1006 commented 9 months ago

4. Paste the following code at the end of ./app/renderer/preload.js:

Thanks a lot! In my case, it works when I replaced the code from the old one.

keithgibson commented 9 months ago

Got it working on macos by following @callmenoodles's great walkthrough, with a couple of changes and additions:

  1. npm install -g asar instead of sudo pacman -S asar

    • requires that npm is already installed
  2. Go to the same resources folder in finder, but at this path (or something like it): /Applications/Notion Enhanced.app/Contents/Resources

  3. To foolproof this step, i recommend copying the full path of app.asar in the above folder by right clicking on app.asar in the bottom of the finder window, then selecting "Copy app.asar as Pathname". My path is /Applications/Notion Enhanced.app/Contents/Resources/app.asar. Then I ran the command sudo asar extract /Applications/Notion Enhanced.app/Contents/Resources/app.asar app, which is functionally the same as that in noodle's guide. Doing it this way doesn't require you to be at the location of the folder in terminal when running the command, as sudo asar extract app.asar app does.

  4. By ./app/renderer/preload.js, noodles [edit: typo] is referring to the 'app' folder in the same folder we're in now. So go into that app folder, then the renderer folder, then find the file preload.js. Open it in something like Text Edit. Paste the code from noodles' post at the very end of the file, like they said, then save the file. That code alone did not fix the issue for me. I had to also paste in the following code, which I found here. Add it above or below the code from noodles' post, then save the file:

    function at(n) {
    // ToInteger() abstract op
    n = Math.trunc(n) || 0;
    // Allow negative indexing from the end
    if (n < 0) n += this.length;
    // OOB access is guaranteed to return undefined
    if (n < 0 || n >= this.length) return undefined;
    // Otherwise, this is just normal property access
    return this[n];
    }
  5. Repacking. Foolproof it by using the full pathname again. My command was sudo asar pack app /Applications/Notion Enhanced.app/Contents/Resources/app.asar

--

And now I have desktop Notion Enhanced again. Thanks @callmenoodles, those from whom you sourced your guide, and @dragonwocky! edit: typo

heliolei commented 9 months ago

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

Thankyou, this worked for me as well, saved the day.!!!

smos08 commented 9 months ago

Got it working on macos by following @callmenoodles's great walkthrough, with a couple of changes and additions:

  1. npm install -g asar instead of sudo pacman -S asar
  • requires that npm is already installed
  1. Go to the same resources folder in finder, but at this path (or something like it): /Applications/Notion Enhanced.app/Contents/Resources
  2. To foolproof this step, i recommend copying the full path of app.asar in the above folder by right clicking on app.asar in the bottom of the finder window, then selecting "Copy app.asar as Pathname". My path is /Applications/Notion Enhanced.app/Contents/Resources/app.asar. Then I ran the command sudo asar extract /Applications/Notion Enhanced.app/Contents/Resources/app.asar app, which is functionally the same as that in noodle's guide. Doing it this way doesn't require you to be at the location of the folder in terminal when running the command, as sudo asar extract app.asar app does.
  3. By ./app/renderer/preload.js, noodles [edit: typo] is referring to the 'app' folder in the same folder we're in now. So go into that app folder, then the renderer folder, then find the file preload.js. Open it in something like Text Edit. Paste the code from noodles' post at the very end of the file, like they said, then save the file. That code alone did not fix the issue for me. I had to also paste in the following code, which I found here. Add it above or below the code from noodles' post, then save the file:

function at(n) { // ToInteger() abstract op n = Math.trunc(n) || 0; // Allow negative indexing from the end if (n < 0) n += this.length; // OOB access is guaranteed to return undefined if (n < 0 || n >= this.length) return undefined; // Otherwise, this is just normal property access return this[n]; } Copy And Save Share Ask Copilot

  1. Repacking. Foolproof it by using the full pathname again. My command was sudo asar pack app /Applications/Notion Enhanced.app/Contents/Resources/app.asar

--

And now I have desktop Notion Enhanced again. Thanks @callmenoodles, those from whom you sourced your guide, and @dragonwocky! edit: typo

this worked great for me, thank you @keithgibson and @callmenoodles

nvmnghia commented 9 months ago

So the actual problem is the old Electron. Is there any PR/plan to upgrade it?

dragonwocky commented 9 months ago

@nvmnghia an update is underway. Most issues like this one have already been fixed, but individual themes and extensions still need to be updated to be compatible. I'm working on it, but I've got some other work to finish first.

Omarahmed16 commented 9 months ago

@dragonwocky, Can you tell us the date that you will solve this proplem because i'm waiting with bated breath🔥.

acerspyro commented 9 months ago

@dragonwocky, Can you tell us the date that you will solve this proplem because i'm waiting with bated breath🔥.

No dates, @dragonwocky is donating their time to this project. They'll get to it when they get to it.

If you want to help get this out faster, you can always donate to them at the link on the bottom of this page, or by clicking here.

image

iliymans commented 9 months ago

I have this issue with Windows. can anybody help me, please?

D1Gz-S3c commented 9 months ago

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

u rock! thanks so much

AbdelrhmanUZaki commented 9 months ago

I have this issue with Windows. can anybody help me, please?

Did you solve it?

deanrobin333 commented 9 months ago

UPDATE: GOT IT TO WORK ON UBUNTU: Modified file on Github

This Notion issue really put me on frets. Though it gave me a change to check out Anytype, and its quite an awesome app considering its offline first. However, I still use and need Notion, as it has a robust formula system.

I managed to repatch the script provided here, and got it to work flawlessly with ubuntu 23.10 mantic minotaur. Key changes

be sure to use the script as root. Most commands require root user, as they have not been written with sudo.

henfiber commented 9 months ago

@deanrobin333 I checked your modified script, there a couple bugs carried from the original script which I have fixed and mentioned in my previous comment here

Without these fixes, if you open the developer tools, you will probably see errors in the console and while Notion loads properly, some features do not work (e.g. Find in page, clicking on links etc.)

In your own script you have to

So, your lines 64-65:

    cat <<EOL >>preload.js
(function __polyfill_2() {

should be modified as:

    cat <<'EOL' >>preload.js

(function __polyfill_2() {
iliymans commented 9 months ago

I have this issue with Windows. can anybody help me, please?

Did you solve it?

No

deanrobin333 commented 9 months ago

@henfiber , we learn everyday. I've also learned best way to use EOL. The script worked, and I could use notion, opening links and searching files. But I read the links you provided and as much as the script worked, the best practise of using EOL, is as you described. Much appreciated. I have modified those changes on the script. Thank you!

AbdelrhmanUZaki commented 9 months ago

I have this issue with Windows. can anybody help me, please?

Did you solve it?

No

I started to use obsidian, it has a lot of plugins that do more than notion enhancer.

FallCheetah7373 commented 8 months ago

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

I think I also replied on discord as well this script doesn't work on linux mint 21.2 I think its because asar is in snap repo and linux mint doesn't ships snap.

Rex-82 commented 8 months ago

For anyone still facing white loading screen even after modifying preload.js with the error:

electron/js2c/renderer_init.js:91 TypeError: require(...)(...) is not a function

Add a semicolon after require('notion-enhancer')('renderer/preload', exports, (js) => eval(js)) in the preload.js file. (should be around line 449-451)

The correct line will then be: require('notion-enhancer')('renderer/preload', exports, (js) => eval(js));

worked for me on windows10

FallCheetah7373 commented 8 months ago

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

I think I also replied on discord as well this script doesn't work on linux mint 21.2 I think its because asar is in snap repo and linux mint doesn't ships snap.

for anyone still facing this on linux mint install asar using

sudo npm i -g asar

and rerun the script provided

lhecht commented 7 months ago

I have this issue with Windows. can anybody help me, please?

Did you solve it?

No

I could solve it with the hints given here: https://github.com/notion-enhancer/notion-repackaged/issues/112#issuecomment-1875146578

iliymans commented 7 months ago

I have this issue with Windows. can anybody help me, please?

Did you solve it?

No

I could solve it with the hints given here: #112 (comment)

I can't fix it . can you solve it with any desk for me?

lhecht commented 7 months ago

I have this issue with Windows. can anybody help me, please?

Did you solve it?

No

I could solve it with the hints given here: #112 (comment)

I can't fix it . can you solve it with any desk for me?

Well, I think all the relevant steps are described for solving this issue on windows. I don't know, what keeps you from solving it, so I don't know how to help you.

iliymans commented 7 months ago

On Wed, Jan 3, 2024 at 18:42 lhecht @.***> wrote:

I have this issue with Windows. can anybody help me, please?

Did you solve it?

No

I could solve it with the hints given here: #112 (comment) https://github.com/notion-enhancer/notion-repackaged/issues/112#issuecomment-1875146578

I can't fix it . can you solve it with any desk for me?

Well, I think all the relevant steps are described for solving this issue on windows. I don't know, what keeps you from solving it, so I don't know how to help you.

When i enter the path its wrong

— Reply to this email directly, view it on GitHub https://github.com/notion-enhancer/notion-repackaged/issues/116#issuecomment-1875527551, or unsubscribe https://github.com/notifications/unsubscribe-auth/AULOVFEU4Y77KQ2B6PZHZO3YMVYNZAVCNFSM6AAAAAA6SFPNW2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZVGUZDONJVGE . You are receiving this because you commented.Message ID: @.***>

krilovskiy commented 7 months ago

@callmenoodles Best solution. Worked for me! Thx!

vfairon commented 6 months ago

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

You are a king !