<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; AHK: Взаимодействие с Chrome]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=17857&amp;type=atom" />
	<updated>2025-03-16T19:42:58Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=17857</id>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162108#p162108" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[1srafel]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43566</uri>
			</author>
			<updated>2025-03-16T19:42:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162108#p162108</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162107#p162107" />
			<content type="html"><![CDATA[<p>Не пробовал.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2025-03-16T19:32:47Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162107#p162107</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162106#p162106" />
			<content type="html"><![CDATA[<p>Нашелся скрипт для Tampermonkey, который копирует куки страницы после ее открытия. Но при запуске с ключом &quot;--headless&quot;, в скрытом окне, копирование не происходит. Правильно понимаю, что в скрытом режиме расширения не отрабатывают?</p>]]></content>
			<author>
				<name><![CDATA[1srafel]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43566</uri>
			</author>
			<updated>2025-03-16T19:11:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162106#p162106</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162103#p162103" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2025-03-15T19:08:41Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162103#p162103</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162102#p162102" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2025-03-15T19:05:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162102#p162102</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162101#p162101" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[1srafel]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43566</uri>
			</author>
			<updated>2025-03-15T18:36:21Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162101#p162101</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162100#p162100" />
			<content type="html"><![CDATA[<p>Думаю, нереально.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2025-03-15T18:21:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162100#p162100</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162099#p162099" />
			<content type="html"><![CDATA[<p>Есть расширение &quot;Copy Cookies&quot;, которое копирует куки со страницы в один клик. По умолчанию расширению назначен хоткей Ctrl+Shift+K. Хотелось бы запускать Хром без видимого окна на определенной интернет странице и выполнять это расширение, чтобы куки этой страницы появлялись в буфере.</p>]]></content>
			<author>
				<name><![CDATA[1srafel]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43566</uri>
			</author>
			<updated>2025-03-15T18:09:35Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162099#p162099</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162098#p162098" />
			<content type="html"><![CDATA[<p>Вы бы лучше сказали, чего конкретно хотите добиться, а не то, как вы именно хотите этого добиться.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2025-03-15T18:05:36Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162098#p162098</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162097#p162097" />
			<content type="html"><![CDATA[<p>Можно ли теоретически запустить скрытый Хром, где вместо ссылки будет js-букмарклет, который запустит нужную ссылку и нажмет хоткей?</p><div class="codebox"><pre><code>Run, %ChromePath% --headless &quot;javascript:...&quot;,, ,PID</code></pre></div>]]></content>
			<author>
				<name><![CDATA[1srafel]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43566</uri>
			</author>
			<updated>2025-03-15T17:55:30Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162097#p162097</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162096#p162096" />
			<content type="html"><![CDATA[<p>Значит, взаимодействовать на уровне клавиш, можно только с видимым окном Хрома?</p>]]></content>
			<author>
				<name><![CDATA[1srafel]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43566</uri>
			</author>
			<updated>2025-03-15T17:49:25Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162096#p162096</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162095#p162095" />
			<content type="html"><![CDATA[<p>Во-первых, скрытое окно не может быть активным, во-вторых, в headless-mode Хром вообще не создаёт окна, даже скрытого.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2025-03-15T17:43:00Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162095#p162095</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162094#p162094" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[1srafel]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43566</uri>
			</author>
			<updated>2025-03-15T16:33:34Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162094#p162094</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162092#p162092" />
			<content type="html"><![CDATA[<p>Поддерживает, запускайте с ключом <em>--headless</em>.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2025-03-15T15:36:44Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162092#p162092</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: AHK: Взаимодействие с Chrome]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=162091#p162091" />
			<content type="html"><![CDATA[<p>Верно ли, что Хром не поддерживает запуск в скрытом режиме, или как-то иначе надо пробовать? - </p><div class="codebox"><pre><code>Run, &quot;%chrome_path%&quot; https://forum.script-coding.com/,, Hide UseErrorLevel, PID</code></pre></div>]]></content>
			<author>
				<name><![CDATA[1srafel]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=43566</uri>
			</author>
			<updated>2025-03-15T14:18:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=162091#p162091</id>
		</entry>
</feed>
