Last active
February 7, 2024 06:36
-
-
Save AppleCEO/2d4557a38602b01f055698afdaadfa0f to your computer and use it in GitHub Desktop.
WKUserScript example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// containerView.swift | |
// WebviewApp | |
// | |
// Created by joon-ho kil on 8/28/19. | |
// Copyright © 2019 길준호. All rights reserved. | |
// | |
import UIKit | |
import WebKit | |
class containerView: UIView { | |
override func draw(_ rect: CGRect) { | |
let contentController = WKUserContentController() | |
let scriptSource = "document.body.style.backgroundColor = `red`;" | |
let script = WKUserScript(source: scriptSource, injectionTime: .atDocumentEnd, forMainFrameOnly: true) | |
contentController.addUserScript(script) | |
let config = WKWebViewConfiguration() | |
config.userContentController = contentController | |
let webView = WKWebView(frame: self.bounds, configuration: config) | |
let url = URL(string: "https://m.shopping.naver.com") | |
let request = URLRequest(url: url!) | |
webView.load(request) | |
addSubview(webView) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment