Skip to content

Attempting to add support for z.ai (GLM)#121

Open
procodingtools wants to merge 5 commits intosrbhptl39:mainfrom
procodingtools:supporting-z-ai
Open

Attempting to add support for z.ai (GLM)#121
procodingtools wants to merge 5 commits intosrbhptl39:mainfrom
procodingtools:supporting-z-ai

Conversation

@procodingtools
Copy link

@procodingtools procodingtools commented Aug 2, 2025

* denotes required fields

Priority*

  • High: This PR needs to be merged first, before other tasks.
  • Medium: This PR should be merged quickly to prevent conflicts due to common changes. (default)
  • Low: This PR does not affect other tasks, so it can be merged later.

Purpose of the PR*

Add initial support for Z.ai (GLM), enabling the project to interact with and utilize z.ai

Changes*

  • Integrated Z.ai (GLM) into the supported websites list
  • Added new ZAdapter
  • Updated README.md
  • Hide original CM Editor content after wrapping to function box

How to check the feature

  1. Switch to this branch
  2. Run pnpm zip
  3. Install the extension package

Reference

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. We will check and reply to you as soon as possible.

@Hit1009
Copy link

Hit1009 commented Aug 6, 2025

Hello @srbhptl39 @k0vah1911pepsi @hayeah,

Considering GLM 4.5 is currently one of the best models for agentic tasks including coding, I believe the support for z.ai should be a top priority. Please add the support for z.ai at the earliest.

Thank you

@srbhptl39
Copy link
Owner

Hello @srbhptl39 @k0vah1911pepsi @hayeah,

Considering GLM 4.5 is currently one of the best models for agentic tasks including coding, I believe the support for z.ai should be a top priority. Please add the support for z.ai at the earliest.

Thank you

Yes on its way

@procodingtools
Copy link
Author

Fixed issue with long text generation (like create new file)

@srbhptl39
Copy link
Owner

srbhptl39 commented Aug 11, 2025

Thanks @procodingtools for adding z.ai support. I gave it a run and found the following:

What Works:
Streaming detection
Function call detection and execution
Other functionalities of inserting instruction and file attachment
Proper rendering of function block

What does not work:
Large files lose indentation and newlines (code formatting breaks)
Page refresh causes parameter clipping for large content due to CodeMirror's virtual container

Recommendations:
Use the automatic copy button to retrieve content after streaming completes
For https://chat.z.ai/, disable streaming detection to avoid issues
Hide CodeMirror with display:none during streaming, then use the copy button to get content and display the function block once streaming finishes
Copy button should only be the source for getting the text from the CodeMirror.
Also lot of other unrelated changes are not required, try to keep changes to minimal and keep a check if website where code is running is chat.z.ai to avoid any memory leak issues

@procodingtools
Copy link
Author

procodingtools commented Aug 11, 2025

Thanks @procodingtools for adding z.ai support. I gave it a run and found the following:

What Works: Streaming detection Function call detection and execution Other functionalities of inserting instruction and file attachment Proper rendering of function block

What does not work: Large files lose indentation and newlines (code formatting breaks) Page refresh causes parameter clipping for large content due to CodeMirror's virtual container

Recommendations: Use the automatic copy button to retrieve content after streaming completes For https://chat.z.ai/, disable streaming detection to avoid issues Hide CodeMirror with display:none during streaming, then use the copy button to get content and display the function block once streaming finishes Copy button should only be the source for getting the text from the CodeMirror. Also lot of other unrelated changes are not required, try to keep changes to minimal and keep a check if website where code is running is chat.z.ai to avoid any memory leak issues

@srbhptl39 i'm not sure if i made a mistake but here's how copy method looks like:
image

image

- removed unecessary usage of getCMContent from rescript.js
@procodingtools
Copy link
Author

procodingtools commented Aug 11, 2025

Found a new workaround to retrieve text from the CM editor without relying on the copy button and without losing indentation. The copy-based approach had several drawbacks:

  • It affects the user’s clipboard and may accidentally overwrite it when the user needs it.
  • It requires using an async clipboard API, which would lead to significant refactoring or force us to rely on messy/unstable synchronous workarounds.

I think this new approach avoids those issues entirely.

Note: tested only on Firefox

@srbhptl39
Copy link
Owner

@procodingtools
Ya this new workaround should work. Good find :)
I had the idea about it that data should reside somewhere inside in the state.

Can you test in chromium based browsers? I find errors regading inline script execution which is not allowed, hence this does work there

console logs:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost:* http://127.0.0.1:* chrome-extension://8802aba4-5c8e-49a6-a1a3-141032a7b1c7/". Either the 'unsafe-inline' keyword, a hash ('sha256-UoJaWpBirtI6DsOG52M8fHmkN+nvqKa0Qi3Rru6gf1A='), or a nonce ('nonce-...') is required to enable inline execution.

Try to see if this can be done without injecting script.

@procodingtools
Copy link
Author

@procodingtools
Ya this new workaround should work. Good find :)
I had the idea about it that data should reside somewhere inside in the state.

Can you test in chromium based browsers? I find errors regading inline script execution which is not allowed, hence this does work there

console logs:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' 'wasm-unsafe-eval' 'inline-speculation-rules' http://localhost:* http://127.0.0.1:* chrome-extension://8802aba4-5c8e-49a6-a1a3-141032a7b1c7/". Either the 'unsafe-inline' keyword, a hash ('sha256-UoJaWpBirtI6DsOG52M8fHmkN+nvqKa0Qi3Rru6gf1A='), or a nonce ('nonce-...') is required to enable inline execution.

Try to see if this can be done without injecting script.

Maybe we have to use chrome.scripting

Since this is a cross browser extension, how to access chrome.x or browser.x ? This project doesn't contains polyfills.js

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

Successfully merging this pull request may close these issues.

3 participants