Giter Club home page Giter Club logo

modheader_selenium's People

Contributors

dependabot[bot] avatar devigo avatar hao1300 avatar hao4 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

modheader_selenium's Issues

Unable to install modheader.xpi on firefox (v. 57) selenium(v. 3.14)

Hi,

Getting following error while using the modheader.xpi provided at path modheader_selenium/modheader.xpi
1548960470996 addons.xpi WARN Add-on {75145e4e-c014-4625-94db-6dbf92f2f6bb} is not correctly signed.
1548960470996 addons.xpi WARN Add-on {75145e4e-c014-4625-94db-6dbf92f2f6bb} is not correctly signed.
1548960470997 addons.xpi WARN Add-on {75145e4e-c014-4625-94db-6dbf92f2f6bb} is not correctly signed.

Also tried to use the Firefox Addon with 2.25 version, getting following stacktrace
1548961004034 addons.xpi-utils WARN addMetadata: Add-on [email protected] is invalid: Error: Invalid addon ID: expected addon ID [email protected], found {ed630365-1261-4ba9-a676-99963d2b4f54} in manifest (resource://gre/modules/addons/XPIProvider.jsm -> resource://gre/modules/addons/XPIProviderUtils.js:1235:15) JS Stack trace: [email protected]:1235:15 < [email protected]:1578:23 < [email protected]:3265:34 < [email protected]:2182:25 < [email protected]:263:12 < [email protected]:730:5 < [email protected]:897:9 < [email protected]:3081:5 < [email protected]:65:9

Can you please add the application id and get it signed as well.
"applications": {
"gecko": {
"id": "{ed630365-1261-4ba9-a676-99963d2b4f54}"
}
}

Domain cannot be resolved

I am not sure if this domain (https://webdriver.bewisse.com) is supposed to work, but now it cannot be resolved (anymore?). At least I cannot set the headers when I use a different domain (because it complains about the unresolved domein). Any thoughts?

Python documentation

Hi,

Not sure if there is any python documentation for loading the extension.
I've tried loading it directly and it said it's an unknown format.

Url filter not working together with VeePN extension

I tested with my code using python + selenium and see that when I've used Mod Header alone, Url filter is working fine. But when I add VeePN extension to Chrome, somehow Url filter stops working then every request get the same referer header

FEATURE REQUEST: Drive modheader from markup

I want to be able to click on a link on a page that opens in a new window, but have a specific header applied on the new window.

It would be cool if I could do this in the markup somehow:

<a href="link" modheader-data-HEADER_NAME="value" target="_blank">link text</a>

or similar.

Or even using javascript's window.open();

getAddHeaderUrl

getAddHeaderUrl( name1, value1, name2, value2, ... )
getAddHeaderUrl( { name1: value1, name2: value2 } )
require( 'chrome-modheader' ).addHeaderUrl  === 'https://webdriver.bewisse.com/add'

[Note][Chrome][Python] New Method

Actually, I found a quite sneaky way without using a Proxy or Extension:

You can change the Headers in continue_request() at my_headers = {"sec-ch-ua-platform": "Android"} .

# resource: https://stackoverflow.com/questions/66227508/selenium-4-0-0-beta-1-how-add-event-listeners-in-cdp

class cdp_listener:
    from typing import Dict

    def __init__(self):
        self.listeners = {}
    async def async_helper(self):
        async with driver.bidi_connection() as connection:
            session, devtools = connection.session, connection.devtools

            for listener in self.listeners.items():
                my_listener = await listener[1]["listener"](connection=connection)

                async for event in my_listener:
                    try:
                        await session.execute(listener[1]["at_event"](event=event, connection=connection))
                    except Exception as e:
                        print(e)

    def trio_helper(self):
        import trio
        trio.run(self.async_helper)

    def start_threaded(self, listeners: Dict[str,Dict[callable, callable]] = {}):
        if listeners:
            self.listeners = listeners

        import threading
        thread = threading.Thread(target=self.trio_helper)
        thread.start()
        return thread

    def add_listeners(self, listeners: Dict[str,Dict[callable, callable]]):
        self.listeners = listeners

    def remove_listener(self, listener:str):
        del self.listeners[listener]

async def all_requests(connection):
    session, devtools = connection.session, connection.devtools
    pattern = map(devtools.fetch.RequestPattern.from_json,[{"urlPattern":"*"}])
    pattern = list(pattern)
    await session.execute(devtools.fetch.enable(patterns=pattern))

    return session.listen(devtools.fetch.RequestPaused)

def continue_request(event, connection):
    print({"type":event.resource_type.to_json(),"frame_id": event.frame_id, "url": event.request.url})
    session, devtools = connection.session, connection.devtools

    headers = event.request.headers.to_json()

    my_headers = {"sec-ch-ua-platform": "Android"}
    headers.update(my_headers)
    my_headers = []
    for item in headers.items():
        my_headers.append(devtools.fetch.HeaderEntry.from_json({"name": item[0], "value": item[1]}))

    return devtools.fetch.continue_request(request_id=event.request_id, headers=my_headers)


cdp_listener = cdp_listener()
thread = cdp_listener.start_threaded(listeners= {"continue":{"listener":all_requests,"at_event":continue_request}})

driver.get('https://modheader.com/headers?product=ModHeader')

How to set url filters

Hello, could you please help me with setting url filter here

I am trying to edit request headers using the following code:

page.visit("chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj/_generated_background_page.html") test = JSON.generate([{ title: 'Selenium', hideComment: true, appendMode: '', headers: [ { enabled: true, name: 'name', value: 'value'} ], respHeaders: [], filters: [] }]) page.execute_script "chrome.storage.local.set({'profiles': #{test}})"

How can I define "filters: []" to set this to specific url, what format should I use?

thanks for help!

Sub requests not redirected

I use modheader for quite a long time. For one or two weeks it stopped working as intended for URL redirection. I redirect simple urls using exact source url and exact target. The problem is that it is still working if I type the URL directly in the address bar but it is not working anymore for subrequests triggered by a website. I installed the last update and the problem is still there.

Thank you.

Modifed Headers always be lowercased

Hey, i have a little problem.
Some sites are case sensitive. With ModHeader all modifed headers always be lowercase and then server side not detecting that.

Example with ModHeader:
xsrf1
Example clear:
xsrf2

How i can set ModHeader to not lowercase my headers :/
Best Regards

Modheader doesn't work webdriver.io

Hello! I try to use modheader in wdio with chrome but I can't install plugin. I use instruction and examples but it doesn't help me. I see
Loading...
If you are still seeing this message after a few seconds, that means ModHeader has not been installed correctly. Please refer to ModHeader Selenium WebDriver doc on how to setup ModHeader for WebDriver correctly.
my wdio.conf.js
const merge = require('deepmerge');
const dotenv = require('dotenv');
const getUsersFile = require('./support/getUsersFile');
const allureReporter = require('@wdio/allure-reporter').default;
const allure = require('allure-commandline');
const chromeModheader = require('chrome-modheader');
dotenv.config();
const drivers = {
chrome: { version: '110.0.5481.77'}};

// Без этого упадет с сертификатом
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';

const baseUrl =
process.env.APP_HOST || process.env.CUSTOM_HOSTNAME || 'https://help.tst.ru';

let specs = ['./test/tests/cabinet-end-to-end/.js', './test/tests/cabinet-mock/.js'];
let localReporter;
if (process.env.ALLURE === 'true') {
localReporter = [
'allure',
{
outputDir: 'allure-results',
disableWebdriverStepsReporting: true
}
];
} else {
localReporter = 'spec';
}

const dockerOptions = process.env.IS_DOCKER ? ['--disable-dev-shm-usage', '--no-sandbox'] : [];

const browsers = {
grid: {
logLevel: 'error',
hostname: 'test.ru',
path: '/wd/v1/quotas/test',
port: 80,
headers: {Authorization: OAuth ${process.env.SURFWAX_TOKEN}},
capabilities: [
{
maxInstances: 15,
browserName: 'chrome',
browserVersion: '96.0',
'goog:chromeOptions': {
extensions: [chromeModheader.getEncodedExtension()],
args: [
'--disable-gpu',
'--lang=ru',
'--window-size=1920,1080',
'--disable-infobars',
'--disable-web-security',
'--disable-popup-blocking',
'--deny-permission-prompts',
...dockerOptions
],
prefs: {
'profile.default_content_setting_values.geolocation': 2
}
},
'selenoid:options': {
env: ['LANG=ru_RU.UTF-8', 'LANGUAGE=ru:en', 'LC_ALL=ru_RU.UTF-8'],
enableVNC: true,
enableVideo: true
},
acceptInsecureCerts: true,
specs: specs
}
],
reporters: [
[
'allure',
{
outputDir: 'allure-results',
disableWebdriverStepsReporting: true
}
]
],
specFileRetries: 1,
specFileRetriesDelay: 0,
specFileRetriesDeferred: true
},
local: {
runner: 'local',
reporters: [localReporter],
logLevel: 'debug',
capabilities: [
{
maxInstances: 1,
browserName: 'chrome',
browserVersion: '96.0',
'goog:chromeOptions': {
extensions: [chromeModheader.getEncodedExtension()],
args: [
'--disable-gpu',
'--disable-infobars',
'--lang=ru',
'--window-size=1920,1080',
'--deny-permission-prompts',
],
prefs: {
'profile.default_content_setting_values.geolocation': 2
}
},
acceptInsecureCerts: true,
specs: [],
}

    ],

}

};

const config = {
async onPrepare() {
await getUsersFile('./users.json');
},
exclude: [],
maxInstances: 20,
bail: 0,
baseUrl: baseUrl,
waitforTimeout: 10000,
connectionRetryTimeout: 150000,
connectionRetryCount: 3,

services: [

        ['selenium-standalone', { logPath: 'logs', installArgs: { drivers }, args: { drivers } }],


    [
        'image-comparison',
        {
            baselineFolder: './screenshots/baseline',
            formatImageName: '{tag}',
            screenshotPath: './screenshots/',
            autoSaveBaseline: true,
            returnAllCompareData: true,
            logLevel: 'silent'
        }
    ]
],
framework: 'mocha',
mochaOpts: {
    ui: 'bdd',
    timeout: 240000
},

afterTest: async function (test, context, {error, result, duration, passed, retries}) {
    await browser.takeScreenshot();
    await browser.mockRestoreAll();
},
onComplete: function () {
    if (process.env.ALLURE === 'true') {
        const reportError = new Error('Could not generate Allure report');
        const generation = allure(['generate', 'allure-results', '--clean']);
        return new Promise((resolve, reject) => {
            const generationTimeout = setTimeout(() => reject(reportError), 5000);

            generation.on('exit', function (exitCode) {
                clearTimeout(generationTimeout);

                if (exitCode !== 0) {
                    return reject(reportError);
                }

                console.log('Allure report successfully generated');
                resolve();
            });
        });
    }
}

};

exports.config = merge.all([config, browsers[process.env.RUNNER || 'local']]);

I got this error

Add headers
Error while adding header
TypeError: Cannot read properties of undefined (reading 'undefined')

Python Example

Hello,

Have you got a Python example for adding response headers with this using normal selenium?

ModHeader makes Selenium detected by Cloudflare

I run my code without mod Header and it passed Cloudflare https://nowsecure.nl, but when I add modHeader extension to Chrome (with/without changing header), it makes Cloudeflare detect Selenium immediately.

I've tested many times and many case, and I guess because of Mod Header changes navigator.plugins so it make Cloudflare detects Selenium
Before adding ModHeader to Chrome
https://i.imgur.com/ZdVgMNH.png
After adding ModHeader to Chrome
https://i.imgur.com/vJoZFFJ.png

Broken in Chrome 109?

I just updated to Chrome 109 today and this broke. Now I get:

15:08:27.916 [Test worker] WARN com.cameraforensics.sitefingerprinting.services.FeatureExtractorService - Couldn't prepare the webdriver: Could not start a new session. Response code 500. Message: unknown error: failed to wait for extension background page to load: chrome-extension://jciacimpfapbkckkegdfngcnbdpabaoi/_generated_background_page.html

again. WebDriver options being used are:

    public static final List<String> DEFAULT_WEBDRIVER_PROPERTIES = Arrays.asList(
            "--kiosk",
            "--headless=chrome",
            "--disable-dev-shm-usage",
            "--ignore-certificate-errors",
            "--disable-blink-features=AutomationControlled",
            "--log-level=DEBUG",
            "--whitelisted-ips",
            "--disable-gpu",
            "--disable-software-rasterizer",
            "--verbose"
    );

When I run it not-headless it all works just fine.

If I run it not-headless, and go to the extension itself and try to view the background page the link to the background page under Inspect views does nothing (nothing happens when you click it):

Screenshot 2023-01-24 at 15 11 09

Interestingly, if I take off headless mode, put in a breakpoint and go to chrome-extension://jciacimpfapbkckkegdfngcnbdpabaoi/_generated_background_page.html it literally takes me no-where - the page stays blank.

Could not install add-on

@hao1300 we're just started noticing an issue (within the past few hours) with the firefox-modheader/modheader.xpi add-on, specifically we're receiving the following errors:

Could not install add-on: /tmp/tmpw048_e__: ERROR_CORRUPT_FILE: The file appears to be corrupt.
Stacktrace:
WebDriverError@chrome://remote/content/shared/webdriver/Errors.jsm:183:5
UnknownError@chrome://remote/content/shared/webdriver/Errors.jsm:510:5
install@chrome://remote/content/marionette/addon.js:86:13

and was wondering whether it was related to your recent efc74ff commit.

Headless mode doesnt work but non headless is fine

I am trying headless mode and non headless is fine for me. But I need to run in headless for my piplelie. I used the following code to run
Path currentRelativePath = Paths.get("mods/ModHeader.crx");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(currentRelativePath.toAbsolutePath().toString()));

     options.addArguments("--headless=chrome");
     ChromeDriver driver = new ChromeDriver(options);
     driver.get("https://chrome.google.com/webstore/detail/modheader-modify-http-hea/idgpnmonknjnojddfkpgkljpfnnfcklj");
     driver.get("https://webdriver.modheader.com/add?keys=user");
     Thread.sleep(5000);

where I need to add keys = user. Its fine on non headless but in healdess it fails and I get the below error

net.serenitybdd.core.exceptions.SerenityManagedException: org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: failed to wait for extension background page to load: chrome-extension://jciacimpfapbkckkegdfngcnbdpabaoi/_generated_background_page.html
from unknown error: page could not be found: chrome-extension://jciacimpfapbkckkegdfngcnbdpabaoi/_generated_background_page.html
Host info: host: 'UK-C02FK7EPML7H', ip: 'fe80:0:0:0:1439:59e7:ffd0:28da%en0'
Build info: version: '4.5.3', revision: '4b786a1e430'
System info: os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '12.6.1', java.version: '17.0.5'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless=chrome], extensions: [Q3IyNAMAAABBAQAAEqgCCqIBMIG...]}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [--headless=chrome], extensions: [Q3IyNAMAAABBAQAAEqgCCqIBMIG...]}}}]

Did anyone face similar issue. No matter what I do, the line where I instantiate doesnt go beyond that line

How to load two profiles via api?

Hey Sir i trying to load profiles via /load and its working fine for 1 profile, but when i trying to upload json with more 1 profiles its crashing extenstion. I do something wrong or it's not supported by extension. I see in normal way (click in popup) i can export multiple profiles by checking boxes, but load via /load api not working.

Examples:
site: https://webdriver.modheader.com/load
1 profile working fine:
https://pastebin.com/raw/7EVfrA5w
2 profiles not working after load:
https://pastebin.com/raw/UYnUYXa6

Best Regards

Chrome doesn't allow crx2 format anymore

Is there a way to download the crx3 version of the the plugin?

Problem

I am using addExtensions method of the latest webdriver which now asks for loading it via a file instead. So I dumped the base64 after decoding it into a file and gave it to it and that's when I got the following error

[session not created: cannot process extension #1 from unknown error: CRX verification failed to parse extension header. Chrome supports only CRX3 format. Does the extension need to be updated?]

I ensured, before raising a ticket here, that it still works with the older version of the webdriver.

Title timeout error

Error :

Wait timed out after 10201ms
at exit (/codebuild/output/src381708701/src/node_modules/@cucumber/cucumber/lib/runtime/parallel/run_worker.js:12:54)
at /codebuild/output/src381708701/src/node_modules/@cucumber/cucumber/lib/runtime/parallel/run_worker.js:25:31
at processTicksAndRejections (node:internal/process/task_queues:96:5)
caused by: VError: a BeforeAll hook errored on worker 3, process exiting: features/support/hooks.js:13: Waiting for title to be "Done"

Browser configuration:

let webdriver = require('selenium-webdriver');
let chrome = require('selenium-webdriver/chrome');
const {getExtension, getAddHeaderUrl} = require("chrome-modheader");
const {until} = require("selenium-webdriver");

const screen = {
    width: 1920,
    height: 1080
};
const buildBrowser = () => {
    var chromeoptions = new chrome.Options();
    chromeoptions.addArguments("headless=new");
    chromeoptions.addArguments("start-maximized"); // open Browser in maximized mode
    chromeoptions.addArguments("disable-infobars"); // disabling infobars
    chromeoptions.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
    chromeoptions.addArguments("--no-sandbox"); // Bypass OS security model
    chromeoptions.addArguments("--enable-javascript");
    chromeoptions.addExtensions(getExtension());
    return new webdriver.Builder().forBrowser('chrome')
        .setChromeOptions(chromeoptions.windowSize(screen))
        .build();

const setupBrowser = async (driver) => {
    await driver.get(getAddHeaderUrl('my-header', 'my-framework'));
    await driver.wait(until.titleIs('Done'), 10000);
    await driver.manage().window().maximize();
    await driver.manage().deleteAllCookies();
}

Chrome Driver version: ChromeDriver 111.0.5563.64
Google Chrome version: Google Chrome 111.0.5563.146

Same issue happened with ChromeDriver 109.0.5414.74 as well.

Any suggestions on how to resolve this issue?

Advertising issues

One day I discovered that there were some advertisements on my page. After a long investigation, I found out that they were inserted by modheader. I think your way of inserting advertisements is very shameful. At the very least, it should be emphasized in the advertisement that this advertisement is from modheader. It was inserted without any prompts. Inserting ads greatly affects the user experience. I have uninstalled on this extension so far.

modheader for chrome didn't work for webdriverio

good morning,
i followed the doc here https://docs.modheader.com/advanced/selenium-webdriver but didn't work for me.
I'm using webdriverio v.7 and this is my wdio.conf.js

`const path = require('path');
const chromeModheader = require('chrome-modheader');
const JOB_ID = process.env.JOB_ID || 'dummyLocal';
const CustomReporter = require('./test/utils/customReporter');
const { suites } = require('./test-suites.conf');
const { hooks } = require('./hooks');

exports.config = {
services: ['devtools'],
/* Specify Test Files /
specs: ['./test/features/**/
.feature'],
/* Define specific suites /
suites,
/
Capabilities /
maxInstances: 1,
acceptInsecureCerts: true,
capabilities: [
{
browserName: 'chrome',
'goog:chromeOptions': {
extensions: [chromeModheader.getEncodedExtension()],
args: [
// '--headless',
'--no-sandbox',
'--incognito',
// '--start-fullscreen',
'--disable-notifications',
],
prefs: {
/

0 ==> default
1 ==> Allow
2 ==> Block
/
// 'profile.managed_default_content_settings.javascript': 2,
// 'profile.managed_default_content_settings.images': 2,
'profile.default_content_setting_values.notifications': 2,
// 'profile.managed_default_content_settings.stylesheets':2,
// 'profile.managed_default_content_settings.cookies': 2,
'profile.managed_default_content_settings.plugins': 2,
'profile.managed_default_content_settings.popups': 2,
'profile.managed_default_content_settings.geolocation': 2,
'profile.managed_default_content_settings.media_stream': 2,
},
},
},
],
before: function () {
browser.url(chromeModheader.getAddHeaderUrl('here i put name of the header', 'here i put value of the header'));
},
/
Level of logging verbosity: trace | debug | info | warn | error | silent /
logLevel: 'debug',
outputDir: path.join(__dirname, '/logs'),
coloredLogs: true, // Enables colors for log output.
sync: true,
bail: 0,
baseUrl: '', //baseUrl is not used because it is overridden by browser.url() in Common.page.js
waitforTimeout: 200000,
connectionRetryTimeout: 200000,
connectionRetryCount: 3,
framework: 'cucumber',
reporters: [
'spec',
[
'cucumberjs-json',
{
jsonFolder: reports/${JOB_ID},
language: 'en',
},
],
CustomReporter,
],
cucumberOpts: {
requireModule: [],
require: ['./test/step-definitions/
.js'],

    // <boolean> show full backtrace for errors
    backtrace: false,

    // <boolean> invoke formatters without executing steps
    dryRun: false,

    // <boolean< Treat ambiguous definitions as errors
    failAmbiguousDefinitions: true,

    // <boolean> abort the run on first failure
    failFast: false,

    // <string[]> (type[:path]) specify the output format, optionally supply PATH to redirect formatter output (repeatable)
    format: ['pretty'],

    // <boolean> disable colors in formatter output
    colors: true,

    // <boolean> hide step definition snippets for pending steps
    snippets: true,

    // <string[]> ("extension:module") require files with the given EXTENSION after requiring MODULE (repeatable)
    name: [],

    // <boolean> hide source uris
    source: false,

    // <string[]> (name) specify the profile to use
    profile: [],

    // <boolean> fail if there are any undefined or pending steps
    strict: true,

    // <string> (expression) only execute the features or scenarios with tags matching the expression
    tagExpression: 'not @pending',

    // <boolean> add cucumber tags to feature or scenario name
    tagsInTitle: false,

    // <number> timeout for step definitions
    timeout: 300000,

    // <boolean> Enable this config to treat undefined definitions as warnings.
    ignoreUndefinedDefinitions: false,

    // <string> specify a custom snippet syntax
    snippetSyntax: undefined,

    // Specify the number of times to retry failing test cases
    retry: 2,

    //Inserts WebdriverIO's globals (e.g. `browser`, `$` and `$$`) into the global environment.
    injectGlobals: true,
},
/* Cucumber-specific hooks */
...hooks,
// onPrepare(),
// onComplete(),

};`

i didn' have any type of error but didn't work correctly.Could you help please?

[USER QUESTION] How to apply JSON encoded profile?

Is it possible to have modheader_selenium look for a JSON encoded user profile in a default location on the filesystem and apply its settings (e.g., request header names and values to be added), or specify the profile location via some arguments, as in:

-u   choose a user profile by name
-f   choose a file location for header definitions

add headers

I want to add some information, such as "test1 = 111 & 2222", which contains "&", so what should I do? i tried to modify the background.js, but it didn't useful

DOES THIS WORK NOW?

I was using this till yesterday and it worked fine. But not anymore?
is there something I am doing wrong?

Screenshot from 2019-11-17 16-32-25

headless

chrome headless mode

WebDriverError: unknown error: failed to wait for extension background page to load: chrome-extension://jciacimpfapbkckkegdfngcnbdpabaoi/_generated_background_page.html

ERR_NAME_NOT_RESOLVED when visiting https://webdriver.modheader.com/add?...

## modheader version

I downloaded it from here: https://github.com/modheader/modheader_selenium/raw/main/chrome-modheader/modheader.crx today.

What I expected to happen:

I expected the call to webdriver.modheader.com to be intercepted by the extension and not to get a ERR_NAME_NOT_RESOLVED error.

Code snippet:

            WebDriverManager.chromedriver().setup();

            List<String> appliedOptions = new ArrayList<>();
            appliedOptions.addAll(DEFAULT_WEBDRIVER_PROPERTIES);

            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments(appliedOptions);
            chromeOptions.addExtensions(new File("/modheader.crx"));
            chromeOptions.setExperimentalOption("excludeSwitches", new String[]{"enable-automation"});
            chromeOptions.setExperimentalOption("useAutomationExtension", false);

            driver = new ChromeDriver(chromeOptions);
            driver.get("https://webdriver.modheader.com/add?Referer=" + URLEncoder.encode(referrer, Charset.defaultCharset()));

Logs:

2022-09-21 19:00:24.514  INFO 77077 --- [nio-8081-exec-2] i.g.bonigarcia.wdm.WebDriverManager      : Using chromedriver 105.0.5195.52 (resolved driver for Chrome 105)
2022-09-21 19:00:24.519  INFO 77077 --- [nio-8081-exec-2] i.g.bonigarcia.wdm.WebDriverManager      : Exporting webdriver.chrome.driver as /Users/me/.cache/selenium/chromedriver/mac-arm64/105.0.5195.52/chromedriver
Starting ChromeDriver 105.0.5195.52 (412c95e518836d8a7d97250d62b29c2ae6a26a85-refs/branch-heads/5195@{#853}) on port 54901
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
[1663783224.875][WARNING]: Deprecated chrome option is ignored: useAutomationExtension
[1663783224.875][WARNING]: Deprecated chrome option is ignored: useAutomationExtension
2022-09-21 19:00:25.465  INFO 77077 --- [ null to remote] o.o.selenium.remote.ProtocolHandshake    : Detected upstream dialect: W3C
2022-09-21 19:00:25.526  WARN 77077 --- [nio-8081-exec-2] o.o.selenium.devtools.CdpVersionFinder   : Unable to find an exact match for CDP version 105, so returning the closest version found: 102
2022-09-21 19:00:25.526  INFO 77077 --- [nio-8081-exec-2] o.o.selenium.devtools.CdpVersionFinder   : Found CDP implementation for version 105 of 102
2022-09-21 19:00:25.758  WARN 77077 --- [nio-8081-exec-2] c.c.s.services.FeatureExtractorService   : Couldn't prepare the webdriver: unknown error: net::ERR_NAME_NOT_RESOLVED
  (Session info: chrome=105.0.5195.125)
Build info: version: '4.2.1', revision: 'ac4d0fdd4a'
System info: host: 'mylaptop.lan', ip: 'fe80:0:0:0:145b:86e7:ade4:4635%en0', os.name: 'Mac OS X', os.arch: 'aarch64', os.version: '12.5.1', java.version: '17.0.3'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [c16bef64676a3c4892a554cc6afc06d6, get {url=https://webdriver.modheader.com/add?Referer=https%3A%2F%2Fsomesite.com}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 105.0.5195.125, chrome: {chromedriverVersion: 105.0.5195.52 (412c95e51883..., userDataDir: /var/folders/yc/p1gcr6s917b...}, goog:chromeOptions: {debuggerAddress: localhost:57302}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: MAC, proxy: Proxy(), se:cdp: ws://localhost:57302/devtoo..., se:cdpVersion: 105.0.5195.125, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: c16bef64676a3c4892a554cc6afc06d6

org.openqa.selenium.WebDriverException: unknown error: net::ERR_NAME_NOT_RESOLVED
  (Session info: chrome=105.0.5195.125)

Issue on Chrome when --disable-web-security option is activated

Hi,

I'm using the modheader extension on Chrome (Selenium + Chromedriver) to inject response header, it works well except when the --disable-web-security is set on Chrome launch arguments.

I'm using Python and when this request is send:
browser.get('https://webdriver.modheader.com/load?profile={"respHeaders":[{"enabled":true,"name":"Timing-Allow-Origin","value":"*"}],"shortTitle":"1","title":"Profile1","version":2}')

I obtain this error:
selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_TUNNEL_CONNECTION_FAILED

I'm using Chrome 107.0.5304.110 and the modheader.crx file gets from this github.

My question : Why the --disable-web-security argument impacts the extension behaviour and how can I solve this ?

Regards

Not working on firefox and chrome for wdio

image

I have tested this on chrome browser for WebdriverIO but did not work

even when I try to send more than one value that also considering as object

one more doubt onPrepare hook , we are creating 'browser.url(chromeModheader.getAddHeaderUrl('accept-encoding', ''));'
but in case of I want to test chrome and firefox at a time how can we make this ? can we make as below right?
browser.url(chromeModheader.getAddHeaderUrl('accept-encoding', ''));'
browser.url(firefoxModheader.getAddHeaderUrl('accept-encoding', ''));'
will this header accept 'x-ak-clientip' and 'x-forwarded-for'?

Load Extension question

Is it possible to use this extension like this?

options.addArguments(
"load-extension=/path to unzipped ");

Looks like there is no error, but the extension is not working...

Thanks!

Issues Reusing the Extension in a New Session with the Same Firefox Profile

I am using selenium with Firefox, and I use a custom firefox profile where I add the extension to the same profile. The first session goes as expected, the extension does the job. But, when I kill that session and restart a new one, the extension doesn't work at all, I tried to clean the temporary Firefox profile folder, but nothing, I got the same issue. Here is step by step what I do:

  1. Create a new Firefox Profile
  2. Start a new session with the new Firefox Profile and using Selenium to add the extension file
  3. Works perfectly, the information is injected in the request Header as expected.
  4. Kill the driver
  5. Start a new session with the exact same configuration as in (2)
  6. The request headers are not modified

Extension Version: 1.0.4
Firefox Version: 84.0.2 (Headless)
Geckodriver Version: 0.28
OS Version: Alpine 3.12.6

Add header in Selenium

Hi,
Im very close to using this but there's only one thing stopping me. In Firefox, when I want to send a request with a header. Without this header, my request is going to fail.

I tried this:

final ProfilesIni pi = new ProfilesIni();
final FirefoxProfile profile = pi.getProfile("default");
profile.setPreference("browser.download.folderList",
      2); // 0: Desktop, 1: Downloads, 2: Custom Location
final Path abs = downloadedFilePath.toAbsolutePath();
profile.setPreference("browser.download.dir", abs.toString());

final String commonPassword = repProperties.getCommonPassword();
final String usernamePassword = username + ":" + commonPassword;
final String encodedString = Base64.getEncoder().encodeToString(usernamePassword.getBytes());

// These prefs dont work. 
/*profile.setPreference("modifyheaders.headers.count", 1);
profile.setPreference("modifyheaders.headers.action0", "Add");
profile.setPreference("modifyheaders.headers.name0", "Authorization");
profile.setPreference("modifyheaders.headers.value0", "Basic " + encodedString);
profile.setPreference("modifyheaders.headers.enabled0", true);
profile.setPreference("modifyheaders.config.active", true);
profile.setPreference("modifyheaders.config.alwaysOn", true);*/

// Neither do these. 
profile.setPreference("modheader.headers.count", 1);
profile.setPreference("modheader.headers.action0", "Add");
profile.setPreference("modheader.headers.name0", "Authorization");
profile.setPreference("modheader.headers.value0", "Basic " + encodedString);
profile.setPreference("modheader.headers.enabled0", true);
profile.setPreference("modheader.headers.config.active", true);
profile.setPreference("modheader.headers.config.alwaysOn", true);

final FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("acceptInsecureCerts", true);
//firefoxOptions.setHeadless(true); sj_todo remove uncomment
firefoxOptions.setProfile(profile);

logger.debug("Creating reports at {}", abs);
final FirefoxDriver webDriver = new FirefoxDriver(firefoxOptions);
webDriver.installExtension("path-to-xpi");
return webDriver;

Another way is to load the modheader profile (that has the header I need) on startup. But I cant find a way to import automatically on startup either.

Any suggestions?

Thanks.

How to Add Request and Response Headers in ModHeaders for selenium

i need add Request Headers and Response Headers in selenium how to add that in my chrome driver.

in Modheaders docs i can see this code to install the extensions. now how to add the headers.

Selenium code in docs

https://modheader.com/docs/advanced/selenium-webdriver
Java Selenium

For Chrome


Path currentRelativePath = Paths.get("chrome-modheader/modheader.crx");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(currentRelativePath.toAbsolutePath().toString()));
ChromeDriver driver = new ChromeDriver(options);
driver.get("https://webdriver.modheader.com/add?test=ModHeader%20Test");
new WebDriverWait(driver, Duration.ofSeconds(500)).until(ExpectedConditions.titleIs("Done"));

using chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj/src/app_v1.html i can inspect and automate that i don't need. instead of that using .crx directly add using from code i need to set.

Screenshot 2024-05-16 at 8 52 45 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.