Nativefier: --injecting multiple js files mangles them in nativefied app

Created on 3 Oct 2017  路  9Comments  路  Source: jiahaog/nativefier

Description

When injecting multiple files, the final rendering of the inject.js file is corrupted

Steps to reproduce issue

test1.js

alert('Test1')

test2.js

console.log('Test2')

Run

nativefier --inject test1.js --inject test2.js --name Github https://github.com

Github.app/Contents/Resources/app/inject/inject.js

alert('Test1')
st2')

Specifications

Version of Nativefier (run nativefier --version): v7.4.1
Version of Node.js (run node --version): v8.5.0
OS: macOS High Sierra 10.13.1

bug

Most helpful comment

I believe the problem as reported is that the user is trying to inject two script files and that just isn't supported. The --inject handler in the build script copies any injected js file to inject.js without any consideration for multiple files.

As to why it's got the strange content rather than just being one file or the other, under the covers it looks like the injection handling functions uses the ncp library to perform file copies and _that_ library uses stream copying, so it's probably overwriting only portions of the file.

Scenario, those two files end with newline characters (\n), it first copies characters 1-21 of the string console.log('Test2')\n and then overwrites characters 1-15 of that with alert('Test1')\n giving you alert('Test1')\nst2')

All 9 comments

@jplot merci du retour 馃憤. Before I give a try at reproducing the issue, one wording nit: when you say "deteriorated", are you saying Nativefier regressed? (Said differently, did it use to work? If yes, when and any idea when it started mangling data?) Thanks.

@ronjouch No it does not work, from the second file inject it corrupts inject.js

No it does not work, from the second file inject it corrupts inject.js

@jplot I get that, but my question is: has it already worked in an earlier version of Nativefier?

@ronjouch Yes, 7.4.0 and 7.4.1

Still not clear, please make a complete sentence.

does not work on Nativefier v7.4.0 and v7.4.1

I believe the problem as reported is that the user is trying to inject two script files and that just isn't supported. The --inject handler in the build script copies any injected js file to inject.js without any consideration for multiple files.

As to why it's got the strange content rather than just being one file or the other, under the covers it looks like the injection handling functions uses the ncp library to perform file copies and _that_ library uses stream copying, so it's probably overwriting only portions of the file.

Scenario, those two files end with newline characters (\n), it first copies characters 1-21 of the string console.log('Test2')\n and then overwrites characters 1-15 of that with alert('Test1')\n giving you alert('Test1')\nst2')

It looks like the behavior now is that one js file is randomly picked. It would be nice to be able to pick.

It seams like this is still an issue. For me, the last --inject ....js wins, and the first one is ignored.

Was this page helpful?
0 / 5 - 0 ratings