Skip to content

Instantly share code, notes, and snippets.

@AppleCEO
Last active February 7, 2024 06:36
Show Gist options
  • Save AppleCEO/2d4557a38602b01f055698afdaadfa0f to your computer and use it in GitHub Desktop.
Save AppleCEO/2d4557a38602b01f055698afdaadfa0f to your computer and use it in GitHub Desktop.
WKUserScript example
//
// 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