From a45ae46bcfcf80200cfc820d5b8e185e5a3d43cf Mon Sep 17 00:00:00 2001 From: Antec Date: Thu, 28 Mar 2024 19:48:47 +0100 Subject: [PATCH] Define the path to Chrome extensions --- RuriLib/Blocks/Selenium/Browser/Methods.cs | 23 ++++--------------- .../Configs/Settings/BrowserSettings.cs | 2 ++ 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/RuriLib/Blocks/Selenium/Browser/Methods.cs b/RuriLib/Blocks/Selenium/Browser/Methods.cs index aedb1dc..c6f9e83 100644 --- a/RuriLib/Blocks/Selenium/Browser/Methods.cs +++ b/RuriLib/Blocks/Selenium/Browser/Methods.cs @@ -15,6 +15,7 @@ using System.Text.RegularExpressions; using Microsoft.CodeAnalysis.Differencing; using System.IO; +using System.Security.Policy; namespace RuriLib.Blocks.Selenium.Browser { @@ -70,27 +71,13 @@ public static class Methods { chromeop.AddArgument("--headless"); } - // Define the path to the directory that contains the Chrome extensions - string extensionsDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UserData", "ChromeExtensions"); - - // Check if the directory exists - if (Directory.Exists(extensionsDir)) - { - // Get all the .crx files in the directory - string[] extensionFiles = Directory.GetFiles(extensionsDir, "*.crx"); - - // Add each extension to the options - foreach (string extensionPath in extensionFiles) - { - chromeop.AddExtension(extensionPath); - } - } - else + else if (data.ConfigSettings.BrowserSettings.ChromeExtensions.Count >0) { + chromeop.AddExtensions(data.ConfigSettings.BrowserSettings.ChromeExtensions + .Where(ext => ext.EndsWith(".crx")) + .Select(ext => Path.Combine(Directory.GetCurrentDirectory(), "UserData", "ChromeExtensions", ext))); - Console.WriteLine("UserData/ChromeExtensions directory does not exist."); - return; } // Initialize the Chrome driver with the options diff --git a/RuriLib/Models/Configs/Settings/BrowserSettings.cs b/RuriLib/Models/Configs/Settings/BrowserSettings.cs index 57f45d3..c262ff7 100644 --- a/RuriLib/Models/Configs/Settings/BrowserSettings.cs +++ b/RuriLib/Models/Configs/Settings/BrowserSettings.cs @@ -12,5 +12,7 @@ public class BrowserSettings public bool LoadOnlyDocumentAndScript { get; set; } = false; public bool DismissDialogs { get; set; } = false; public List BlockedUrls { get; set; } = new(); + + public List ChromeExtensions { get; set; } = new(); } }