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

enable_browser_notification

enable_browser_notification($enable=true,$show=false,$refresh=true); - управление показом и доступностью браузерных уведомлений.

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

  • $enable – разрешить (true) или запретить (false) уведомления браузера
  • $show – показывать (true) или не показывать (false) уведомления браузера
  • $refresh – обновить (true) или не обновить (false) браузер, после изменения этой настройки

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

    Пример использования
    <?php
    // Scenario: Enabling and disabling browser notifications with testing on a notifications API demo page
    // 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 enable_browser_notification function
    
    // Enable browser notifications with show parameter
    $result = WEB::$browser->enable_browser_notification(true, true);
    echo "\n\nBrowser notifications enabled with show = true: " . ($result ? "Yes" : "No");
    
    // Navigate to a website to test browser notifications
    $url = "https://delch.github.io/notifications-api/";
    WEB::$browser->navigate($url);
    WEB::$browser->wait_js(2);
    
    echo "\n\nNavigated to: " . $url;
    echo "\nPage loaded with browser notifications enabled";
    
    // Set input `Notification title`
    DOM::$input->set_inner_text_by_number(0, "test 1");
      
    // Set input `Notification body`
    DOM::$input->set_inner_text_by_number(1, "test 2");
    
    // Click button `Send`  (first button on page)
    DOM::$button->click_by_number(0);
    
    // Disable browser notifications
    $result2 = WEB::$browser->enable_browser_notification(false, false, false);
    
    if ($result2) {
        echo "\n\nSuccessfully disabled browser notifications";
    } else {
        echo "\n\nFailed to disable browser notifications";
    }
    
    // Остановить работу
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:7010"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>browser.xxxxxxxxx</font><hr>")
    
    # 1
    echo("1. Включим уведомления : ");
    echo(browser.enable_browser_notification(true,true,false));
    
    # 2
    echo("\n2. Покажем уведомление : ");
    echo(browser.navigate("https://delch.github.io/notifications-api/"),"<br>");
    input.set_inner_text_by_number(0, "test 1");
    input.set_inner_text_by_number(1, "test 2");
    button.click_by_number(0);
    sleep(2);
    
    # 3
    echo("3. Отключим уведомления : ");
    echo(browser.enable_browser_notification(false,false,false));
    
    # 4 
    echo("\n4. Попробуем показать снова: ");
    echo(button.click_by_number(0));
    
    # конец
    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.enable_dom_storage</font><hr>");
    				
    			// 1
    			echo("1. Включим уведомления : ");
    			echo(browser.enable_browser_notification(true,true,false));
    
    			// 2
    			echo("\n2. Покажем уведомление : ");
    			echo(browser.navigate("https://delch.github.io/notifications-api/")+"<br>");
    			input.set_inner_text_by_number(0, "test 1");
    			input.set_inner_text_by_number(1, "test 2");
    			button.click_by_number(0);
    			sleep(2);
    
    			// 3
    			echo("3. Отключим уведомления : ");
    			echo(browser.enable_browser_notification(false,false,false));
    
    			// 4 
    			echo("\n4. Попробуем показать снова: ");
    			echo(button.click_by_number(0));
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:7010";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>browser.enable_java_script</font><hr>");
    
    // 1
    echo("1. Включим уведомления : ");
    echo(browser.enable_browser_notification(true,true,false));
    
    // 2
    echo("\n2. Покажем уведомление : ");
    echo(browser.navigate("https://delch.github.io/notifications-api/")+"<br>");
    input.set_inner_text_by_number(0, "test 1");
    input.set_inner_text_by_number(1, "test 2");
    button.click_by_number(0);
    app.sleep(2);
    
    // 3
    echo("3. Отключим уведомления : ");
    echo(browser.enable_browser_notification(false,false,false));
    
    // 4 
    echo("\n4. Попробуем показать снова: ");
    echo(button.click_by_number(0));
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

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