@dimkoff

Доступ из chrome.dom.openOrClosedShadowRoot к iframe?

Manifest v3
{
	"version": "1.0.0",
	"name": "PAC",
	"manifest_version": 3,
	"permissions": [
		"webRequest",
		"webRequestAuthProvider"
	],
	"host_permissions": [
		"<all_urls>"
	],
	"background": {
		"service_worker": "background.js"
	},
	"content_scripts": [{
		"all_frames": true,
		"js": [
			"content.js"
			],
		"matches": [ "<all_urls>" ],
		"run_at": "document_start"
	}],
	"web_accessible_resources": [{
		"resources": ["interceptor.js"],
		"matches": ["<all_urls>"]
	}]
}

Пример страницы
<!DOCTYPE html>
<html lang="ru">
	<head></head>
	<body>
		<div id="example">
			<div>
				#shadow-root (close)
				<iframe src="Другой домен">
					#document
					<!DOCTYPE html>
					<html lang="en-US" dir="ltr">
						<head></head>
						<body>
							#shadow-root (close)
							<div>
								<div id="content"><div>
							<div>
						</body>
					</html>
				</iframe>
			<div>
		</div>
	</body>
</html>

Мне нужно получить доступ к
#content
.
Но не могу получить доступ к документу iframe.
content.js
var shadowRoot = chrome.dom.openOrClosedShadowRoot(document.getElementById("example").firstChild);
console.log(shadowRoot.firstChild.contentDocument)

contentDocument - выдает null.


В Firefox это можно сделать так:
content.document.getElementById("example")
.firstChild.openOrClosedShadowRoot.firstChild.contentDocument
.body.openOrClosedShadowRoot.querySelector("#content")


Есть ли способ? или что делаю не так?
  • Вопрос задан
  • 75 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы