humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений

set_screen_resolution

set_screen_resolution($width=-1,$height=-1,$pixelDepth=-1); - задать данные о разрешении экрана в JS движок. Задает navigator : (width, height, pixelDepth) и их дубликаты (availWidth,availHeight,colorDepth) (Доступна с версии 4.10.1)

Функция на вход принимает параметры:

  • $width – ширина экрана (пиксели) navigator.width и navigator.availWidth, при -1 - используется значение по умолчанию
  • $height – высота экрана (пиксели) navigator.height и navigator.availHeight, при -1 - используется значение по умолчанию
  • $pixelDepth – глубина пикселей (биты) navigator.pixelDepth и navigator.colorDepth, при -1 - используется значение по умолчанию

    После отработки функция возвращает результат своей работы в скрипт :
  • true – успешно задали
  • false – задать не удалось

    Пример использования
    <?php
    // Scenario: Demonstrates how to set the browser screen resolution to simulate different display configurations
    // Path to the init.php file for connecting to the XHE API
    $xhe_host = "localhost:7010";
    if (!isset($path)){
        // Path to the init.php file for connecting to the XHE API
        $path = "../../../Templates/init.php";
        // Including init.php grants access to all classes and functionality for working with the XHE API
        require($path);
    }
    
    // The following code demonstrates the usage of the set_screen_resolution function
    
    // Set screen resolution for HD (1920x1080)
    $width = 1920;
    $height = 1080;
    $pixelDepth = 24;
    
    $result = WEB::$browser->set_screen_resolution($width, $height, $pixelDepth);
    
    // Display the result
    if ($result) {
        echo "\n\nSuccessfully set screen resolution";
        echo "\nWidth: " . $width . "px";
        echo "\nHeight: " . $height . "px";
        echo "\nPixel Depth: " . $pixelDepth . "bpp";
    } else {
        echo "\n\nFailed to set screen resolution";
    }
    
    // Остановить работу
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7024"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>browser.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1. Зададим разрешение 1024x768:16: ")
    echo(browser.set_screen_resolution(1024,768,16),"<br>")
    
    # 2 
    echo("2. Перейдем на страницу для детектирвоания браузера : ")
    echo(browser.navigate("https://browserleaks.com/javascript"),"<br>")
    sleep(7)
    
    # 3
    echo("3. Зададим разрешение 1024x768:24: ")
    echo(browser.set_screen_resolution(1024,768,24),"<br>")
    
    # 4 
    echo("3. Перейдем на страницу для детектирвоания браузера : ")
    echo(browser.navigate("https://browserleaks.com/javascript"),"<br>")
    sleep(7)
    
    # 5
    echo("5. Зададим разрешение  2560x1440:24 : ")
    echo(browser.set_screen_resolution(2560,1440,24),"<br>")
    
    
    # 6 
    echo("6. Перейдем на страницу для детектирвоания браузера : ")
    echo(browser.navigate("http://www.whoer.net"),"<br>")
    sleep(2)
    anchor.get_by_attribute("class","btn-more").focus()
    anchor.get_by_attribute("class","btn-more").send_mouse_click()
    sleep(5)
    span.get_by_attribute("class","cont window-size-data",false).scroll_to_view(0)
    sleep(5)
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>browser.set_screen_resolution</font><hr>");
    				
    			// 1 
    			echo("1. Зададим разрешение 1024x768:24: ");
    			echo(browser.set_screen_resolution(1024,768,24)+"<br>");
    
    			// 2 
    			echo("2. Перейдем на страницу для детектирования браузера : ");
    			echo(browser.navigate("http://www.whoer.net")+"<br>");
    			sleep(2);
    			anchor.get_by_attribute("class","btn-more").focus();
    			anchor.get_by_attribute("class","btn-more").send_mouse_click();
    			sleep(5);
    			span.get_by_outer_html("<span>platform</span>",false).ensure_visible();
                sleep(5);
    
    			// 3
    			echo("3. Зададим разрешение  2560x1440:24 : ");
    			echo(browser.set_screen_resolution(2560,1440,24)+"<br>");
    
    
    			// 4 
    			echo("4. Перейдем на страницу для детектирования браузера : ");
    			echo(browser.navigate("http://www.whoer.net")+"<br>");
    			sleep(2);
    			anchor.get_by_attribute("class","btn-more").focus();
    			anchor.get_by_attribute("class","btn-more").send_mouse_click();
    			sleep(5);
    			span.get_by_attribute("class","cont window-size-data",false).ensure_visible();
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7022";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>browser.set_accept_language</font><hr>");
    
    // 1 
    echo("1. Зададим разрешение 1024x768:24: ");
    echo(browser.set_screen_resolution(1024,768,24)+"<br>");
    
    // 2 
    echo("2. Перейдем на страницу для детектирования браузера : ");
    echo(browser.navigate("http://www.whoer.net")+"<br>");
    app.sleep(2);
    anchor.get_by_attribute("class","btn-more").focus();
    anchor.get_by_attribute("class","btn-more").send_mouse_click();
    app.sleep(5);
    span.get_by_outer_html("<span>platform</span>",false).ensure_visible();
    app.sleep(5);
    
    // 3
    echo("3. Зададим разрешение  2560x1440:24 : ");
    echo(browser.set_screen_resolution(2560,1440,24)+"<br>");
    
    
    // 4 
    echo("4. Перейдем на страницу для детектирования браузера : ");
    echo(browser.navigate("http://www.whoer.net")+"<br>");
    app.sleep(2);
    anchor.get_by_attribute("class","btn-more").focus();
    anchor.get_by_attribute("class","btn-more").send_mouse_click();
    app.sleep(5);
    span.get_by_attribute("class","cont window-size-data",false).ensure_visible();
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    Browser    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум
    .