Skip to content

Commit b5a9fd3

Browse files
committed
Profiles and Stelth features added to StepBrowser
1 parent 9d17c7d commit b5a9fd3

15 files changed

+1833
-14
lines changed

Src/StepBrowser/ProfileModel.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ public function rules()
2424
[['user_agent'], 'string'],
2525
[['user_agent'], 'required'],
2626

27+
[['language'], 'string'],
28+
[['language'], 'required'],
29+
30+
[['webgl_vendor'], 'string'],
31+
[['webgl_vendor'], 'required'],
32+
33+
[['webgl_renderer'], 'string'],
34+
[['webgl_renderer'], 'required'],
35+
36+
[['platform'], 'string'],
37+
[['platform'], 'required'],
38+
39+
[['fix_hairline'], 'boolean'],
40+
2741
[['proxy'], 'string'],
2842

2943
[['window_size'], 'string'],

Src/StepBrowser/StepBrowserComponent.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function createNewProfile(array $profileConfig)
8989

9090
$profile = Yii::createObject($config);
9191
if (!$profile->validate() || !$profile->save()) {
92-
throw new InvalidConfigException(Json::encode($profile->errors()));
92+
throw new InvalidConfigException(Json::encode($profile->errors));
9393
}
9494
return $profile;
9595
}
@@ -158,6 +158,10 @@ protected function getChromeArgsumentsForProfile(ProfileModel $profile)
158158
$chromeArguments = [];
159159
array_push($chromeArguments, "--window-size={$profile->window_size}");
160160
array_push($chromeArguments, "--user-agent={$profile->user_agent}");
161+
array_push($chromeArguments, "--lang={$profile->language}");
162+
array_push($chromeArguments, "--gpu-vendor-id={$profile->webgl_vendor}");
163+
array_push($chromeArguments, "--renderer={$profile->webgl_vendor}");
164+
array_push($chromeArguments, "--accept-lang={$profile->language}");
161165
if (!empty($profile->proxy)) {
162166
array_push($chromeArguments, "--proxy-server={$profile->proxy}");
163167
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Zakharov\Yii2SeleniumTools\StepBrowser;
4+
5+
use Facebook\WebDriver\WebDriver;
6+
use SapiStudio\SeleniumStealth\SeleniumStealth;
7+
use Zakharov\Yii2SeleniumTools\StepBrowser\ProfileModel;
8+
9+
class StepSeleniumStealth extends SeleniumStealth
10+
{
11+
/**
12+
* Static factory method to create a new StepSeleniumStealth instance from a driver object and a profile model
13+
*
14+
* @param WebDriver $driver
15+
* @param ProfileModel $profile
16+
* @return static
17+
*/
18+
public static function forProfile(WebDriver $driver, ProfileModel $profile)
19+
{
20+
$instance = new static(
21+
$driver,
22+
"", //'user_agent'
23+
[], // 'languages'
24+
$profile->webgl_vendor, //'vendor'
25+
$profile->platform, //'platform'
26+
$profile->webgl_vendor, //'webgl_vendor'
27+
$profile->webgl_renderer, //'renderer'
28+
$profile->fix_hairline ?? false, //'fix_hairline'
29+
true //'run_on_insecure_origins'
30+
);
31+
$instance->usePhpWebriverClient();
32+
return $instance;
33+
}
34+
35+
/**
36+
* SeleniumStealth::makeStealth()
37+
*
38+
* @return
39+
*/
40+
public function makeStealth()
41+
{
42+
$this->with_utils();
43+
$this->chrome_app();
44+
$this->chrome_runtime();
45+
$this->iframe_content_window();
46+
$this->media_codecs();
47+
//$this->navigator_languages();
48+
$this->navigator_permissions();
49+
$this->navigator_plugins();
50+
// $this->navigator_vendor();
51+
$this->navigator_webdriver();
52+
//$this->user_agent_override();
53+
$this->webgl_vendor_override();
54+
$this->window_outerdimensions();
55+
$this->additionalEvades();
56+
if ($this->fix_hairline) {
57+
$this->evaluateOnNewDocument(self::loadFileData($this->jsPath . "hairline.fix.js"));
58+
}
59+
return $this->driver;
60+
}
61+
}

Src/migrations/m000000_000001_create_step_browser_profiles_table.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,27 @@ public function safeUp()
1717
$this->createTable('{{%step_browser_profiles}}', [
1818
'id' => $this->primaryKey(),
1919
'uuid' => $this->string(),
20+
'type' => $this->string(),
2021
'title' => $this->string(),
22+
'os' => $this->string(),
2123
'user_agent' => $this->text(),
24+
'language' => $this->text(),
25+
'time_zone' => $this->text(),
26+
'geo' => $this->string(),
2227
'proxy' => $this->string(),
2328
'window_size' => $this->string(),
29+
'webgl_vendor' => $this->text(),
30+
'webgl_renderer' => $this->text(),
31+
'webrtc' => $this->string(),
32+
'canvas' => $this->string(),
2433
'chrome_binary' => $this->text(),
34+
'audio_context' => $this->string(),
35+
'fonts' => $this->text(),
36+
'media_hardware' => $this->text(),
37+
'platform' => $this->text(),
38+
'fix_hairline' => $this->boolean()->defaultValue(false),
39+
'local_storage' => $this->string(),
40+
'extentions_storage' => $this->string(),
2541
'webdriver_binary' => $this->text(),
2642
'created_at' => $this->dateTime(),
2743
'updated_at' => $this->dateTime(),

0 commit comments

Comments
 (0)