Patching Vivaldi with batch scripts
-
@oudstand Thank you.
I understand that to get the best speed in Vivaldi, this is the correct setting:
-
@barbudo2005 No the other way around - Enable portals by turning that option OFF.
-
@Pathduck Thank you.
-
Since the batch script in the OP is broken now that
window.html
is the one to be modified and notbrowser.html
anymore. And I wasn't able to get any of the newer batch scripts posted here to work on Windows, I modified the script posted by @Christoph142.I just changed all instances of
browser.html
andbrowser.bak.html
towindow.html
andwindow.bak.html
respectively. Which looks to have worked perfectly. Thanks to @debiedowner for the script and @Christoph142 for posting it.Here's the modified script:
:: Author: debiedowner @echo off REM make current directory work when run as administrator cd "%~dp0" set installPath="C:\Users\Steve.Bachand\AppData\Local\Vivaldi\Application\" echo Searching at: %installPath% for /f "tokens=*" %%a in ('dir /a:-d /b /s %installPath%') do ( if "%%~nxa"=="window.html" set latestVersionFolder=%%~dpa ) if "%latestVersionFolder%"=="" ( pause & exit ) else ( echo Found latest version folder: "%latestVersionFolder%" ) if not exist "%latestVersionFolder%\window.bak.html" ( echo Creating a backup of your original window.html file. copy "%latestVersionFolder%\window.html" "%latestVersionFolder%\window.bak.html" ) echo copying js files to custom.js type *.js > "%latestVersionFolder%\custom.js" echo patching window.html file type "%latestVersionFolder%\window.bak.html" | findstr /v "</body>" | findstr /v "</html>" > "%latestVersionFolder%\window.html" echo ^<script src="custom.js"^>^</script^> >> "%latestVersionFolder%\window.html" echo ^</body^> >> "%latestVersionFolder%\window.html" echo ^</html^> >> "%latestVersionFolder%\window.html" pause
-
In the last stable update 6.4.3160.42 or in the previous custom.js stopped working.
My files are:
browser.html:
<!DOCTYPE html> <html> <head> <!-- Keep the styling in sync with ./window.html --> <meta charset="UTF-8" /> <title>Vivaldi</title> <link rel="stylesheet" href="style/common.css" /> <link rel="stylesheet" href="chrome://vivaldi-data/css-mods/css" /> </head> <body> <div id="app" /> <script src="vendor-bundle.js"></script> <script src="background-common-bundle.js"></script> <script src="bundle.js"></script> </body> </html>
window.html
<!-- Vivaldi window document --> <!DOCTYPE html> <html> <head> <!-- Keep the styling in sync with ./browser.html --> <meta charset="UTF-8"> <title>Vivaldi</title> <link rel="stylesheet" href="style/common.css"> <link rel="stylesheet" href="chrome://vivaldi-data/css-mods/css"> </head> <body> <script src="custom.js"></script> </body> </html>
What could be the cause of this problem?
-
@explorerthegeneral this hasn't worked for me. or do i need to put the files in the window file first and then it will work from then on?
-
Windows
Here is a modified Version without the need to edit the Installation Path(If Vivaldi is installed as a user):
:: Author: debiedowner :: Editor: Phobos @echo off REM make current directory work when run as administrator cd "%~dp0" set installPath="%localappdata%\Vivaldi\Application\" echo Searching at: %installPath% for /f "tokens=*" %%a in ('dir /a:-d /b /s %installPath%') do ( if "%%~nxa"=="window.html" set latestVersionFolder=%%~dpa ) if "%latestVersionFolder%"=="" ( echo No window.html found in "%latestVersionFolder%" pause & exit ) else ( echo Found latest version folder: "%latestVersionFolder%" ) if not exist "%latestVersionFolder%\window.bak.html" ( echo Creating a backup of your original window.html file. copy "%latestVersionFolder%\window.html" "%latestVersionFolder%\window.bak.html" ) echo copying js files to custom.js type *.js > "%latestVersionFolder%\custom.js" echo patching window.html file type "%latestVersionFolder%\window.bak.html" | findstr /v "</body>" | findstr /v "</html>" > "%latestVersionFolder%\window.html" echo ^<script src="custom.js"^>^</script^> >> "%latestVersionFolder%\window.html" echo ^</body^> >> "%latestVersionFolder%\window.html" echo ^</html^> >> "%latestVersionFolder%\window.html" pause
-
This doesn't seem to work on Mac. It places the custom script file in the folder, but it doesn't edit the browser.html file.
This is what my custom script looks like:
#!/bin/bash # Original version by Isildur, adapted by luetage # Quit Vivaldi osascript -e 'quit app "Vivaldi.app"' # Find path to Framework folder of current version and save it as variable findPath="`find /Applications/Vivaldi.app -name Vivaldi\ Framework.framework`" # Copy custom js file to Vivaldi.app cp "/Applications/Vivaldi Mods/global-media-controls.js" "$findPath"/Resources/vivaldi/ # Save path to window.html as variable browserHtml="$findPath"/Resources/vivaldi/window.html # Insert references, if not present, and save to temporary file sed 's| </body>| <script src="global-media-controls.js"></script></body>|' "$browserHtml" > "$browserHtml".temp # Backup original file cp "$browserHtml" "$browserHtml".bak # Overwrite mv "$browserHtml".temp "$browserHtml" # Pause script read -rsp $'Press [Enter] to restart Vivaldi...\n' # Open Vivaldi open /Applications/Vivaldi.app
-
@NylaTheWolf Nowadays the
window.html
file is being edited. Things have changed. Editingbrowser.html
doesn’t do anything. That’s not to say you don’t have an issue, but I can’t tell because I’m no longer on macOS. Troubleshoot it.And I don’t know who edited the first post, but they obviously edited the script as well and made it confusing. The variable is still called browserHtml, which makes zero sense.
-
@luetage Yeah but it seems that browserHtml is just a variable for the window.html path, if I'm reading it correctly. Shouldn't it still edit window.html.
-
@NylaTheWolf Variable names notwithstanding, the problem with your patching script is this line:
# Insert references, if not present, and save to temporary file sed 's| </body>| <script src="global-media-controls.js"></script></body>|' "$browserHtml" > "$browserHtml".temp
You should instead have the following:
# Insert references, if not present, and save to temporary file sed 's|</body>| <script src="global-media-controls.js"></script></body>|' "$browserHtml" > "$browserHtml".temp
Notice the lack of space indents between the
|
and</body>
.The problem was that
sed
would fail because it couldn't match on that specified text, since the</body>
tag is no longer indented like before.
Anyways, I will shortly share a modified version of the script by me, the one in the first post is woefully outdated. Stay tuned!
-
@AltCode It worked! Thank you so much!!!
-
macOS
Here is the modified script of @luetage's adaption of @Isildur's original script I am currently using:
#!/bin/sh -eu # Original version by Isildur, adapted by luetage, further modified by AltCode # Save path to custom.js files as a variable jsPath="/PATH/TO/DIR" # Path to dir where your custom.js files are located (e.g. "$HOME/Documents/Vivaldi/mods") # Save name of Vivaldi application as a variable installName="Vivaldi" # installName="Vivaldi Snapshot" # Uncomment this line to apply patch to the snapshot version instead # Save full path to Vivaldi application as a variable installPath="/Applications/$installName.app" # Find path to Framework folder of current version and save it as a variable resourcesPath="$(find "$installPath" -name "Vivaldi Framework.framework")/Resources/vivaldi" # Save full path to window.html as a variable windowHtml="$resourcesPath/window.html" # Create variable to save all html patch lines jsLines="" # Ask to reapply patch if already done before if [ -d "$resourcesPath/load" ]; then echo "$installName.app has already been patched before" read -p "Reapply patch anyways? (Y/N): " confirm if [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]; then rm -fr "$resourcesPath/load" cp "$windowHtml.bak" "$windowHtml" else exit fi fi # Close Vivaldi if open if pgrep -qx "$installName"; then echo "Waiting for $installName.app to close..." osascript -e "quit app \"$installName.app\"" # Make sure Vivaldi is fully closed before continuing while pgrep -qx "$installName"; do sleep 1 done else installOpen=0 fi # Backup original window.html file if it has never been backed up before if [ ! -e "$windowHtml.bak" ]; then echo "Creating a backup of window.html..." cp "$windowHtml" "$windowHtml.bak" # sleep 1 fi # Create folder within $resourcesPath to save custom.js files mkdir -p "$resourcesPath/load" # Change directory to path with custom.js files cd "$jsPath" # Iterate over custom.js files for customJs in *.js; do # Save html patch line jsLines+=" <script src=\"load/$customJs\"></script>\n" # Copy custom.js file into Vivaldi echo "Copying $customJs..." cp "$customJs" "$resourcesPath/load" # sleep 1 done # Patch window.html sed -i "" -e "s|</body>|$jsLines</body>|" "$windowHtml" echo "Finished patching window.html" # Reopen Vivaldi if closed if [ "${installOpen:-1}" = 1 ]; then # sleep 1 echo "Reopening $installName.app..." open "$installPath" fi
The
browserHtml
variable is no more! That should hopefully clear the confusions currently seen in the script from the first post.I also added some safeguards so that the script waits on its own for Vivaldi to close before patching it (rather than you waiting for Vivaldi to close before manually finishing the script with the enter key), and so that when you rerun the script (either because you forgot you used it before or you used it again by accident), it will tell you that you don't have to use it again. But if you do, it won't endlessly add duplicate
<script src="custom.js"></script>
lines into thewindow.html
file every time the script is rerun.The only things that need to be altered in this version is the variable at the very beginning of the script,
jsPath
. The variableinstallName
can also be altered so that the script patches the snapshot version instead of the stable version.
History
- 2024-08-07: The script can now patch multiple JS files as opposed to just one. This means you only have to specify the directory where you are saving your JS files with
jsPath
. - 2024-11-16: Fixed a problem that could occur when copying JS files in the cases where your
jsPath
directory contains folders with spaces in their names. - 2024-12-04: Slight optimization when patching
window.html
withsed
.
- 2024-08-07: The script can now patch multiple JS files as opposed to just one. This means you only have to specify the directory where you are saving your JS files with
-
Here's the mac script with logging each step and not having to hard-code the script names, you can place multiple js scripts in a location (PATH_TO_JS_SCRIPTS) and setup that path once and this will take care of placing everything in the right place and also insert the script tag in widnows.html
I have tested this and it is working, let me know if something needs to be changed or something isn't right
#!/bin/bash # Function for logging log() { echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" } log "Starting Vivaldi JS Modification Script..." # Quit Vivaldi log "Closing Vivaldi browser..." osascript -e 'quit app "Vivaldi.app"' # Find path to Framework folder of current version and save it as variable findPath="`find /Applications/Vivaldi.app -name Vivaldi\ Framework.framework`" log "Found Vivaldi Framework at: $findPath" # switch to the js script directory, replace PATH_TO_SCRIPTS with actual path to your JS scripts cd PATH_TO_SCRIPTS log "Changed directory to: $(pwd)" # Get all JS files in the mods directory jsFiles=(*.js) log "Found JS files:" for file in "${jsFiles[@]}"; do log " - $file" done # Copy all JS files to Vivaldi.app log "Copying JS files to Vivaldi resources..." for file in "${jsFiles[@]}"; do cp "/Users/dipanker/mod/js/$file" "$findPath/Resources/vivaldi/" log " Copied: $file" done # Save path to window.html as variable browserHtml="$findPath"/Resources/vivaldi/window.html log "Window.html location: $browserHtml" # Backup original file cp "$browserHtml" "$browserHtml".bak log "Created backup at: $browserHtml.bak" # Create script tags for all JS files scriptTags="" for file in "${jsFiles[@]}"; do scriptTags="${scriptTags} <script src=\"$file\"></script>\n" done log "Adding script tags to window.html..." # Insert references before </body> tag and save to temporary file sed "s|</body>|$scriptTags</body>|" "$browserHtml" > "$browserHtml".temp # Overwrite mv "$browserHtml".temp "$browserHtml" log "Updated window.html successfully" # Pause script log "Modifications complete." read -rsp $'Press [Enter] to restart Vivaldi...\n' # Open Vivaldi log "Starting Vivaldi..." open /Applications/Vivaldi.app log "Script completed successfully"
-
@Phobos said in Patching Vivaldi with batch scripts:
Here is a modified Version without the need to edit the Installation Path(If Vivaldi is installed as a user):
Does it works with Vivaldi installed by winget ?
And if I would have installed both Vivaldi.Vivaldi and Vivaldi.Vivaldi.Snapshot will work for both ? -
@tomaasz said in Patching Vivaldi with batch scripts:
@Phobos said in Patching Vivaldi with batch scripts:
Here is a modified Version without the need to edit the Installation Path(If Vivaldi is installed as a user):
Does it works with Vivaldi installed by winget ?
Yes, it should because there's no difference installing with or without winget
And if I would have installed both Vivaldi.Vivaldi and Vivaldi.Vivaldi.Snapshot will work for both ?
It uses the latest Version found so that would be the snapshot. I tried installing Vivaldi.Vivaldi AND Vivaldi.Vivaldi.Snapshot. But it updated Vivaldi.Vivaldi to Vivaldi.Vivaldi.Snapshot so I only have one version now anyway. So I don't know how you managed installing both packages. If you show me how to install both with winget, I'll be happy to rewrite the script.