<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Взаимодействие с Chrome]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=17857</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17857&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Взаимодействие с Chrome».]]></description>
		<lastBuildDate>Sun, 16 Mar 2025 19:42:58 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162108#p162108</link>
			<description><![CDATA[<p>Видимо, перестали поддерживаться <a href="https://stackoverflow.com/questions/45372066/is-it-possible-to-run-google-chrome-in-headless-mode-with-extensions">https://stackoverflow.com/questions/453 … extensions</a>.</p>]]></description>
			<author><![CDATA[null@example.com (1srafel)]]></author>
			<pubDate>Sun, 16 Mar 2025 19:42:58 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162108#p162108</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162107#p162107</link>
			<description><![CDATA[<p>Не пробовал.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 16 Mar 2025 19:32:47 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162107#p162107</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162106#p162106</link>
			<description><![CDATA[<p>Нашелся скрипт для Tampermonkey, который копирует куки страницы после ее открытия. Но при запуске с ключом &quot;--headless&quot;, в скрытом окне, копирование не происходит. Правильно понимаю, что в скрытом режиме расширения не отрабатывают?</p>]]></description>
			<author><![CDATA[null@example.com (1srafel)]]></author>
			<pubDate>Sun, 16 Mar 2025 19:11:08 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162106#p162106</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162103#p162103</link>
			<description><![CDATA[<p>Только зачем такой мудрёный js-код?<br /></p><div class="codebox"><pre><code>js := &quot;window.open(&#039;https://forum.script-coding.com/&#039;)&quot;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 15 Mar 2025 19:08:41 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162103#p162103</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162102#p162102</link>
			<description><![CDATA[<p>Да, но только в обычном окне. Такой код запускает js из адресной строки:<br /></p><div class="codebox"><pre><code>js := &quot;(function(){var targetUrl=&#039;https://forum.script-coding.com/&#039;;window.open(targetUrl)})();&quot;
RunJsFromChromeAddressBar(js)

RunJsFromChromeAddressBar(js, title := &quot;ahk_class Chrome_WidgetWin_1 ahk_exe chrome.exe&quot;) {
   static WM_GETOBJECT := 0x3D
        , ROLE_SYSTEM_TEXT := 0x2A
        , STATE_SYSTEM_FOCUSABLE := 0x100000
        , SELFLAG_TAKEFOCUS := 0x1
        , AccAddrBars := []
   
   if !hwnd := WinExist(title) {
      MsgBox Окно Хрома не найдено
      return
   }
   if !AccAddrBars.HasKey(hwnd) {
      SendMessage, WM_GETOBJECT, 0, 1, Chrome_RenderWidgetHostHWND1, ahk_id %hwnd%
      AccChrome := AccObjectFromWindow(hwnd)
      AccAddrBars[hwnd] := SearchElement(AccChrome, {Role: ROLE_SYSTEM_TEXT, State: STATE_SYSTEM_FOCUSABLE})
   }
   AccAddrBar := AccAddrBars[hwnd]
   AccAddrBar.accValue(0) := &quot;javascript:&quot; . js
   Sleep, 100
   AccAddrBar.accSelect(SELFLAG_TAKEFOCUS, 0)
   Sleep, 100
   Loop {
      ControlSend,, {Enter}, ahk_id %hwnd%, Chrome Legacy Window
      Sleep, 200
      if AccAddrBar.accValue(0) != &quot;javascript:&quot; . js
         break
      Sleep, 100
   }
}

SearchElement(parentElement, params)
{
   found := true
   for k, v in params {
      try {
         if (k = &quot;ChildCount&quot;)
            (parentElement.accChildCount != v &amp;&amp; found := false)
         else if (k = &quot;State&quot;)
            (!(parentElement.accState(0) &amp; v) &amp;&amp; found := false)
         else
            (parentElement[&quot;acc&quot; . k](0) != v &amp;&amp; found := false)
      }
      catch 
         found := false
   } until !found
   if found
      Return parentElement
   
   for k, v in AccChildren(parentElement)
      if obj := SearchElement(v, params)
         Return obj
}

AccObjectFromWindow(hWnd, idObject = 0) {
   static IID_IDispatch   := &quot;{00020400-0000-0000-C000-000000000046}&quot;
        , IID_IAccessible := &quot;{618736E0-3C3D-11CF-810C-00AA00389B71}&quot;
        , OBJID_NATIVEOM  := 0xFFFFFFF0, VT_DISPATCH := 9, F_OWNVALUE := 1
        , h := DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;oleacc&quot;, &quot;Ptr&quot;)
        
   VarSetCapacity(IID, 16), idObject &amp;= 0xFFFFFFFF
   DllCall(&quot;ole32\CLSIDFromString&quot;, &quot;Str&quot;, idObject = OBJID_NATIVEOM ? IID_IDispatch : IID_IAccessible, &quot;Ptr&quot;, &amp;IID)
   if DllCall(&quot;oleacc\AccessibleObjectFromWindow&quot;, &quot;Ptr&quot;, hWnd, &quot;UInt&quot;, idObject, &quot;Ptr&quot;, &amp;IID, &quot;PtrP&quot;, pAcc) = 0
      Return ComObject(VT_DISPATCH, pAcc, F_OWNVALUE)
}

AccChildren(Acc) {
   static VT_DISPATCH := 9
   Loop 1  {
      if ComObjType(Acc, &quot;Name&quot;) != &quot;IAccessible&quot;  {
			error := &quot;Invalid IAccessible Object&quot;
         break
		}
      try cChildren := Acc.accChildCount
      catch
         Return &quot;&quot;
      if !cChildren
         Return
      Children := []
      VarSetCapacity(varChildren, cChildren*(8 + A_PtrSize*2), 0)
      res := DllCall(&quot;oleacc\AccessibleChildren&quot;, &quot;Ptr&quot;, ComObjValue(Acc), &quot;Int&quot;, 0
                                                , &quot;Int&quot;, cChildren, &quot;Ptr&quot;, &amp;varChildren, &quot;IntP&quot;, cChildren)
      if (res != 0) {
         error := &quot;AccessibleChildren DllCall Failed&quot;
         break
      }
      Loop % cChildren  {
         i := (A_Index - 1)*(A_PtrSize*2 + 8)
         child := NumGet(varChildren, i + 8)
         Children.Push( (b := NumGet(varChildren, i) = VT_DISPATCH) ? AccQuery(child) : child )
         ( b &amp;&amp; ObjRelease(child) )
      }
   }
   if error
      ErrorLevel := error
   else
      Return Children.MaxIndex() ? Children : &quot;&quot;
}

AccQuery(Acc) {
   static IAccessible := &quot;{618736e0-3c3d-11cf-810c-00aa00389b71}&quot;, VT_DISPATCH := 9, F_OWNVALUE := 1
	try Return ComObject(VT_DISPATCH, ComObjQuery(Acc, IAccessible), F_OWNVALUE)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 15 Mar 2025 19:05:25 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162102#p162102</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162101#p162101</link>
			<description><![CDATA[<p>А есть ли способ запустить букмарклет, как ссылку?</p><div class="codebox"><pre><code>Run, %ChromePath% &quot;javascript:(function(){var targetUrl=&#039;https://forum.script-coding.com/&#039;;window.open(targetUrl)})();&quot;,, ,PID</code></pre></div><p>То есть, выполнить такой букмарклет, открывающий веб-страницу:</p><div class="codebox"><pre><code>javascript:(function(){var targetUrl=&#039;https://forum.script-coding.com/&#039;;window.open(targetUrl)})();</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (1srafel)]]></author>
			<pubDate>Sat, 15 Mar 2025 18:36:21 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162101#p162101</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162100#p162100</link>
			<description><![CDATA[<p>Думаю, нереально.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 15 Mar 2025 18:21:06 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162100#p162100</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162099#p162099</link>
			<description><![CDATA[<p>Есть расширение &quot;Copy Cookies&quot;, которое копирует куки со страницы в один клик. По умолчанию расширению назначен хоткей Ctrl+Shift+K. Хотелось бы запускать Хром без видимого окна на определенной интернет странице и выполнять это расширение, чтобы куки этой страницы появлялись в буфере.</p>]]></description>
			<author><![CDATA[null@example.com (1srafel)]]></author>
			<pubDate>Sat, 15 Mar 2025 18:09:35 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162099#p162099</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162098#p162098</link>
			<description><![CDATA[<p>Вы бы лучше сказали, чего конкретно хотите добиться, а не то, как вы именно хотите этого добиться.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 15 Mar 2025 18:05:36 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162098#p162098</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162097#p162097</link>
			<description><![CDATA[<p>Можно ли теоретически запустить скрытый Хром, где вместо ссылки будет js-букмарклет, который запустит нужную ссылку и нажмет хоткей?</p><div class="codebox"><pre><code>Run, %ChromePath% --headless &quot;javascript:...&quot;,, ,PID</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (1srafel)]]></author>
			<pubDate>Sat, 15 Mar 2025 17:55:30 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162097#p162097</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162096#p162096</link>
			<description><![CDATA[<p>Значит, взаимодействовать на уровне клавиш, можно только с видимым окном Хрома?</p>]]></description>
			<author><![CDATA[null@example.com (1srafel)]]></author>
			<pubDate>Sat, 15 Mar 2025 17:49:25 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162096#p162096</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162095#p162095</link>
			<description><![CDATA[<p>Во-первых, скрытое окно не может быть активным, во-вторых, в headless-mode Хром вообще не создаёт окна, даже скрытого.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 15 Mar 2025 17:43:00 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162095#p162095</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162094#p162094</link>
			<description><![CDATA[<p>В итоге хотел в скрытое окно слать хоткей, но не реагирует. В чем может быть недочет в данном коде? Без &quot; --headless&quot; (с видимым окном) он работает -<br /></p><div class="codebox"><pre><code>DetectHiddenWindows, On
SetTitleMatchMode, 2

ChromePath := &quot;E:\chrome\chrome.exe&quot;
URLaddress := &quot;https://forum.script-coding.com/&quot;

  Run, %ChromePath% --headless %URLaddress%,, ,PID ;Hide,PID

  WinWait, ahk_pid %PID%,, 3
  If ErrorLevel
  {
    MsgBox, Не дождались окна
    Return
  }
  Sleep 6000

  WinGet, hwnd, ID, Chrome ahk_class Chrome_WidgetWin_1
  WinActivate, ahk_id %hwnd%
  WinWaitActive, ahk_id %hwnd%
  ControlFocus, ahk_id %hwnd%

  ControlSend, ahk_parent, {Ctrl Down}{Shift Down}{sc25}{Shift Up}{Ctrl Up}, ahk_id %hwnd%
  WinClose, ahk_id %hwnd%

  MsgBox %PID%`n`n%Clipboard%</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (1srafel)]]></author>
			<pubDate>Sat, 15 Mar 2025 16:33:34 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162094#p162094</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162092#p162092</link>
			<description><![CDATA[<p>Поддерживает, запускайте с ключом <em>--headless</em>.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sat, 15 Mar 2025 15:36:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162092#p162092</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=162091#p162091</link>
			<description><![CDATA[<p>Верно ли, что Хром не поддерживает запуск в скрытом режиме, или как-то иначе надо пробовать? - </p><div class="codebox"><pre><code>Run, &quot;%chrome_path%&quot; https://forum.script-coding.com/,, Hide UseErrorLevel, PID</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (1srafel)]]></author>
			<pubDate>Sat, 15 Mar 2025 14:18:51 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=162091#p162091</guid>
		</item>
	</channel>
</rss>
