Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need to get browser's active tab url for windows and linux #64

Open
dsoftware763 opened this issue Feb 21, 2020 · 12 comments
Open

need to get browser's active tab url for windows and linux #64

dsoftware763 opened this issue Feb 21, 2020 · 12 comments

Comments

@dsoftware763
Copy link

dsoftware763 commented Feb 21, 2020

can anyone help me to add this feature

@post2seth
Copy link

i need this too, can anyone help?

@codewaseem
Copy link

Same here

@jcpatac
Copy link

jcpatac commented Jun 1, 2020

I would love to have this functionality too. Can someone point us to the right direction?

@post2seth
Copy link

post2seth commented Jun 1, 2020 via email

@hanselke
Copy link

hanselke commented Jun 4, 2020

it works for me on a mac. would need it to be working on windows/linux as well too. Any idea whats the issue?

@post2seth
Copy link

post2seth commented Jun 4, 2020 via email

@timenox
Copy link

timenox commented Jul 26, 2020

is it working on windows and linux ???

@tkainrad
Copy link
Contributor

tkainrad commented Jan 29, 2022

There is a tool written in Go that can parse the active browser tab's URL from Chrome's session files: https://github.com/lemnos/chrome-session-dump

Presumably, this tool could be bundled within active-win, or its parsing code ported to NodeJS. This should work on both Windows and Linux. It might even work with all Chromium-based browsers.

I tested it on Linux already. Unfortunately, I don't have the time to do a PR currently. So, if anyone with some Go experience wants to take a look ;)

@majidbigdeli
Copy link

Hello

You can use UI Automation in Windows

Example my code in c++ for chrome

// MathLibrary.cpp : Defines the exported functions for the DLL.
#include "pch.h" // use stdafx.h in Visual Studio 2017 and earlier
#include <AtlBase.h>
#include <UIAutomation.h>
#include <comutil.h>
#include "Chrome.h"
#pragma comment(lib, "comsuppw.lib")

BSTR chrome_geturl(HWND hwnd) {

	CoInitialize(NULL);
	CComBSTR empty(L"");
	BSTR r = empty;
	while (true)
	{
		if (!hwnd)
			break;
		if (!IsWindowVisible(hwnd))
			continue;


		CComQIPtr<IUIAutomation> uia;
		if (FAILED(uia.CoCreateInstance(CLSID_CUIAutomation)) || !uia)
			break;

		CComPtr<IUIAutomationElement> root;
		if (FAILED(uia->ElementFromHandle(hwnd, &root)) || !root)
			break;


		CComPtr<IUIAutomationCondition> condition;

		//URL's id is 0xC354, or use UIA_EditControlTypeId for 1st edit box
		uia->CreatePropertyCondition(UIA_ControlTypePropertyId,
			CComVariant(0xC354), &condition);

		//or use edit control's name instead
		//uia->CreatePropertyCondition(UIA_NamePropertyId,
		//      CComVariant(L"Address and search bar"), &condition);

		CComPtr<IUIAutomationElement> edit;
		if (FAILED(root->FindFirst(TreeScope_Descendants, condition, &edit))
			|| !edit)
			break; //maybe we don't have the right tab, continue...

		CComVariant url;
		if (FAILED(edit->GetCurrentPropertyValue(UIA_ValueValuePropertyId, &url)))
			break;
		r = url.bstrVal;
		break;
	}
	CoUninitialize();
	return (_bstr_t)r;

};


BSTR getChromeUrl(HWND hwnd)
{
	BSTR r = chrome_geturl(hwnd);
	return r;
}

@anis-dr
Copy link

anis-dr commented Apr 8, 2022

Does anyone have a solution for URLs on windows?

@wrgoto
Copy link
Contributor

wrgoto commented Apr 13, 2022

One option is to use browser extensions to append the URL to the window title, then parse it after retrieving it from active win.

@creaz35
Copy link

creaz35 commented Jun 8, 2022

same issue with windows 11 url is missing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests