JeViCo Posted April 21, 2023 Share Posted April 21, 2023 First of all, browser is created via createBrowser. I've added some in-game settings to adjust browsers's width and height. Changing settings triggers resizeBrowser function with a small delays between calls (100 ms). At some random points browser's content becomes invisible until something happens in browser or it gains a focus. I've tryied to find the issue myself by doing this: 1. Using math.floor on browser size 2. Using sizes that can be devided by two 3. Using different variations of setBrowserRenderingPaused 4. Increasing delays between each call to 1s does nothing 5. Changing blend modes (cuz i'm using webbrowser as material) The only thing that works is recreating the browser over and over again Link to comment
JeViCo Posted April 21, 2023 Author Share Posted April 21, 2023 (edited) Steps to reproduce: 1. Execute /createTestBrowser command 2. Try dragging scrollbar Sample code: local function getFakeHtml() iprint("ok") return "<html><body><h2>Hello world<h2></body></html>" end local browser local size = 200 addCommandHandler("createTestBrowser", function() browser = createBrowser(size, size, true, false) setBrowserAjaxHandler(browser, "assets/index.html", getFakeHtml) addEventHandler("onClientBrowserCreated", browser, function () loadBrowserURL(browser, "http://mta/local/assets/index.html") addEventHandler("onClientRender", root, function() dxDrawImage(200, 200, size, size, browser) end) iprint("created") end) end) addEventHandler("onClientResourceStart", resourceRoot, function() local scx, scy = guiGetScreenSize() local width, height = 200, 20 local scroll = guiCreateScrollBar((scx - width)/2, (scy - height)/2, width, height, true, false) showCursor(true) addEventHandler("onClientGUIScroll", scroll, function() local scrollAmount = guiScrollBarGetScrollPosition(scroll) size = 200 + (scrollAmount/100 * 200) resizeBrowser(browser, size, size) end) end) Edited April 21, 2023 by JeViCo Link to comment
FLUSHBICEPS Posted April 23, 2023 Share Posted April 23, 2023 The browsers content might not be fully loaded when resizeBrowser is called Try this one local browser local size = 200 local newSize = size local function getFakeHtml() iprint("ok") return "<html><body><h2>Hello world<h2></body></html>" end addCommandHandler("createTestBrowser", function() browser = createBrowser(size, size, true, false) setBrowserAjaxHandler(browser, "assets/index.html", getFakeHtml) addEventHandler("onClientBrowserCreated", browser, function () loadBrowserURL(browser, "http://mta/local/assets/index.html") addEventHandler("onClientRender", root, function() if newSize ~= size then resizeBrowser(browser, newSize, newSize) size = newSize end dxDrawImage(200, 200, size, size, browser) end) iprint("created") end) end) addEventHandler("onClientResourceStart", resourceRoot, function() local scx, scy = guiGetScreenSize() local width, height = 200, 20 local scroll = guiCreateScrollBar((scx - width)/2, (scy - height)/2, width, height, true, false) showCursor(true) addEventHandler("onClientGUIScroll", scroll, function() local scrollAmount = guiScrollBarGetScrollPosition(scroll) newSize = 200 + (scrollAmount/100 * 200) end) end) Not sure if it will solve the prob but you can give it a try Link to comment
JeViCo Posted May 19, 2023 Author Share Posted May 19, 2023 Interesting fact. If browser have some active input with blinking caret, it'll stay there while browser's content will remain invisible. It seems to be a GUI issue. I've managed to solve this issue in a dumb way. To make browser's content visible again you have to make it repaint itself by modifying the HTML contents, so i did this: executeCommandHandler(browser, "document.head.innerHTML = document.head.innerHTML") Keep in mind that your HTML should have head tag or other non important element you can work with. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now